mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 10:25:36 +00:00
resync with spectre git, fixes winterz render problem
svn path=/trunk/KDE/kdegraphics/okular/; revision=734041
This commit is contained in:
parent
161ebbc47a
commit
f3a717f412
|
@ -15,8 +15,8 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU gv; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA
|
||||
*
|
||||
* Author: Tim Theisen Systems Programmer
|
||||
* Internet: tim@cs.wisc.edu Department of Computer Sciences
|
||||
|
@ -55,7 +55,6 @@
|
|||
*/
|
||||
#define USE_ACROREAD_WORKAROUND
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
@ -69,6 +68,8 @@
|
|||
#endif
|
||||
#include <ctype.h>
|
||||
|
||||
#include "spectre-utils.h"
|
||||
|
||||
#include "ps.h"
|
||||
|
||||
#ifdef BSD4_2
|
||||
|
@ -106,13 +107,13 @@ static int dsc_strncmp(s1, s2, n)
|
|||
{
|
||||
char *tmp;
|
||||
|
||||
if (strncasecmp(s1, s2, n) == 0)
|
||||
if (_spectre_strncasecmp(s1, s2, n) == 0)
|
||||
return 0;
|
||||
if (s2[n-1] == ':'){
|
||||
tmp = (char *) PS_malloc(n*sizeof(char));
|
||||
strncpy(tmp, s2, (n-1));
|
||||
tmp[n-1]=' ';
|
||||
if (strncasecmp(s1, tmp, n) == 0){
|
||||
if (_spectre_strncasecmp(s1, tmp, n) == 0){
|
||||
PS_free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
@ -172,7 +173,6 @@ typedef struct FileDataStruct_ *FileData;
|
|||
|
||||
typedef struct FileDataStruct_ {
|
||||
FILE *file; /* file */
|
||||
int file_desc; /* file descriptor corresponding to file */
|
||||
int filepos; /* file position corresponding to the start of the line */
|
||||
char *buf; /* buffer */
|
||||
int buf_size; /* size of buffer */
|
||||
|
@ -423,13 +423,13 @@ psscan(const char *filename, int scanstyle)
|
|||
}
|
||||
|
||||
doc->ref_count = 1;
|
||||
doc->filename = strdup (filename);
|
||||
doc->filename = _spectre_strdup (filename);
|
||||
doc->beginheader = position;
|
||||
section_len = line_len;
|
||||
|
||||
text[0] = '\0';
|
||||
sscanf(line, "%%!%256s %*s", text);
|
||||
doc->format = strdup (text);
|
||||
doc->format = _spectre_strdup (text);
|
||||
|
||||
text[0] = '\0';
|
||||
sscanf(line, "%*s %256s", text);
|
||||
|
@ -453,7 +453,7 @@ psscan(const char *filename, int scanstyle)
|
|||
CHECK_MALLOCED(doc);
|
||||
memset(doc, 0, sizeof(struct document));
|
||||
doc->ref_count = 1;
|
||||
doc->filename = strdup (filename);
|
||||
doc->filename = _spectre_strdup (filename);
|
||||
doc->default_page_orientation = NONE;
|
||||
doc->orientation = NONE;
|
||||
}
|
||||
|
@ -629,7 +629,7 @@ psscan(const char *filename, int scanstyle)
|
|||
* name. Case insensitive compares are only used for
|
||||
* PaperSize comments.
|
||||
*/
|
||||
if (strcasecmp(doc->media[0].name, dmp->name) == 0) {
|
||||
if (_spectre_strcasecmp(doc->media[0].name, dmp->name) == 0) {
|
||||
PS_free(doc->media[0].name);
|
||||
doc->media[0].name = (char *)PS_malloc(strlen(dmp->name)+1);
|
||||
CHECK_MALLOCED(doc->media[0].name);
|
||||
|
@ -659,7 +659,7 @@ psscan(const char *filename, int scanstyle)
|
|||
* name. Case insensitive compares are only used for
|
||||
* PaperSize comments.
|
||||
*/
|
||||
if (strcasecmp(doc->media[doc->nummedia].name,
|
||||
if (_spectre_strcasecmp(doc->media[doc->nummedia].name,
|
||||
dmp->name) == 0) {
|
||||
PS_free(doc->media[doc->nummedia].name);
|
||||
doc->media[doc->nummedia].name =
|
||||
|
@ -696,7 +696,7 @@ psscan(const char *filename, int scanstyle)
|
|||
* name. Case insensitive compares are only used for
|
||||
* PaperSize comments.
|
||||
*/
|
||||
if (strcasecmp(doc->media[doc->nummedia].name,
|
||||
if (_spectre_strcasecmp(doc->media[doc->nummedia].name,
|
||||
dmp->name) == 0) {
|
||||
doc->media[doc->nummedia].width = dmp->width;
|
||||
doc->media[doc->nummedia].height = dmp->height;
|
||||
|
@ -907,7 +907,7 @@ psscan(const char *filename, int scanstyle)
|
|||
* name. Case insensitive compares are only used for
|
||||
* PaperSize comments.
|
||||
*/
|
||||
if (strcasecmp(cp, dmp->name) == 0) {
|
||||
if (_spectre_strcasecmp(cp, dmp->name) == 0) {
|
||||
doc->default_page_media = dmp;
|
||||
page_media_set = 1;
|
||||
break;
|
||||
|
@ -1058,7 +1058,7 @@ continuepage:
|
|||
* name. Case insensitive compares are only used for
|
||||
* PaperSize comments.
|
||||
*/
|
||||
if (strcasecmp(cp, dmp->name) == 0) {
|
||||
if (_spectre_strcasecmp(cp, dmp->name) == 0) {
|
||||
doc->pages[doc->numpages].media = dmp;
|
||||
break;
|
||||
}
|
||||
|
@ -1454,7 +1454,6 @@ ps_gettext(line, next_char)
|
|||
/*----------------------------------------------------------*/
|
||||
|
||||
#define FD_FILE (fd->file)
|
||||
#define FD_FILE_DESC (fd->file_desc)
|
||||
#define FD_FILEPOS (fd->filepos)
|
||||
#define FD_LINE_BEGIN (fd->line_begin)
|
||||
#define FD_LINE_END (fd->line_end)
|
||||
|
@ -1486,7 +1485,6 @@ static FileData ps_io_init(file)
|
|||
|
||||
rewind(file);
|
||||
FD_FILE = file;
|
||||
FD_FILE_DESC = fileno(file);
|
||||
FD_FILEPOS = ftell(file);
|
||||
FD_BUF_SIZE = (2*LINE_CHUNK_SIZE)+1;
|
||||
FD_BUF = PS_XtMalloc(FD_BUF_SIZE);
|
||||
|
@ -1946,6 +1944,16 @@ static int blank(line)
|
|||
return *cp == '\n' || *cp== '\r' || (*cp == '%' && (line[0] != '%' || line[1] != '%'));
|
||||
}
|
||||
|
||||
void
|
||||
pscopy (FILE *from, FILE *to, Document d, long begin, long end)
|
||||
{
|
||||
FileData fd;
|
||||
|
||||
fd = ps_io_init(from);
|
||||
pscopyuntil(fd, to, begin, end, NULL);
|
||||
ps_io_exit(fd);
|
||||
}
|
||||
|
||||
void
|
||||
pscopyheaders (FILE *from, FILE *to, Document d)
|
||||
{
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU gv; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA
|
||||
*
|
||||
* Author: Tim Theisen Systems Programmer
|
||||
* Internet: tim@cs.wisc.edu Department of Computer Sciences
|
||||
|
@ -173,6 +173,16 @@ void psgetpagebox (
|
|||
#endif
|
||||
);
|
||||
|
||||
void pscopy (
|
||||
#if NeedFunctionPrototypes
|
||||
FILE *,
|
||||
FILE *,
|
||||
Document,
|
||||
long,
|
||||
long
|
||||
#endif
|
||||
);
|
||||
|
||||
void pscopyheaders (
|
||||
#if NeedFunctionPrototypes
|
||||
FILE *,
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_DEVICE_H
|
||||
|
|
|
@ -15,15 +15,21 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* For stat */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "spectre-document.h"
|
||||
#include "spectre-private.h"
|
||||
#include "spectre-exporter.h"
|
||||
|
||||
struct SpectreDocument
|
||||
{
|
||||
|
@ -228,6 +234,86 @@ spectre_document_get_page (SpectreDocument *document,
|
|||
return page;
|
||||
}
|
||||
|
||||
void
|
||||
spectre_document_save (SpectreDocument *document,
|
||||
const char *filename)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
FILE *from;
|
||||
FILE *to;
|
||||
|
||||
if (stat (document->doc->filename, &stat_buf) != 0) {
|
||||
document->status = SPECTRE_STATUS_SAVE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
from = fopen (document->doc->filename, "r");
|
||||
if (!from) {
|
||||
document->status = SPECTRE_STATUS_SAVE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
to = fopen (filename, "w");
|
||||
if (!to) {
|
||||
document->status = SPECTRE_STATUS_SAVE_ERROR;
|
||||
fclose (from);
|
||||
return;
|
||||
}
|
||||
|
||||
pscopy (from, to, document->doc, 0, stat_buf.st_size - 1);
|
||||
|
||||
fclose (from);
|
||||
fclose (to);
|
||||
|
||||
document->status = SPECTRE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
spectre_document_save_to_pdf (SpectreDocument *document,
|
||||
const char *filename)
|
||||
{
|
||||
SpectreExporter *exporter;
|
||||
SpectreStatus status;
|
||||
unsigned int i;
|
||||
|
||||
exporter = spectre_exporter_new (document, SPECTRE_EXPORTER_FORMAT_PDF);
|
||||
if (!exporter) {
|
||||
document->status = SPECTRE_STATUS_NO_MEMORY;
|
||||
return;
|
||||
}
|
||||
|
||||
status = spectre_exporter_begin (exporter, filename);
|
||||
if (status) {
|
||||
document->status = status == SPECTRE_STATUS_NO_MEMORY ?
|
||||
SPECTRE_STATUS_NO_MEMORY : SPECTRE_STATUS_SAVE_ERROR;
|
||||
spectre_exporter_free (exporter);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < spectre_document_get_n_pages (document); i++) {
|
||||
status = spectre_exporter_do_page (exporter, i);
|
||||
if (status)
|
||||
break;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
document->status = status == SPECTRE_STATUS_NO_MEMORY ?
|
||||
SPECTRE_STATUS_NO_MEMORY : SPECTRE_STATUS_SAVE_ERROR;
|
||||
spectre_exporter_free (exporter);
|
||||
return;
|
||||
}
|
||||
|
||||
status = spectre_exporter_end (exporter);
|
||||
spectre_exporter_free (exporter);
|
||||
|
||||
if (status) {
|
||||
document->status = status == SPECTRE_STATUS_NO_MEMORY ?
|
||||
SPECTRE_STATUS_NO_MEMORY : SPECTRE_STATUS_SAVE_ERROR;
|
||||
} else {
|
||||
document->status = SPECTRE_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
struct document *
|
||||
_spectre_document_get_doc (SpectreDocument *document)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_DOCUMENT_H
|
||||
|
@ -118,7 +118,20 @@ unsigned int spectre_document_get_language_level (SpectreDocument *documen
|
|||
*/
|
||||
SpectrePage *spectre_document_get_page (SpectreDocument *document,
|
||||
unsigned int page_index);
|
||||
|
||||
/*! Save document as filename. This function can fail
|
||||
@param document the document that will be saved
|
||||
@param filename the path where document will be saved
|
||||
@see spectre_document_status
|
||||
*/
|
||||
void spectre_document_save (SpectreDocument *document,
|
||||
const char *filename);
|
||||
/* Save document as a pdf document. This function can fail
|
||||
@param document the document that will be saved
|
||||
@param filename the path where document will be saved as pdf
|
||||
@see spectre_document_status
|
||||
*/
|
||||
void spectre_document_save_to_pdf (SpectreDocument *document,
|
||||
const char *filename);
|
||||
SPECTRE_END_DECLS
|
||||
|
||||
#endif /* SPECTRE_DOCUMENT_H */
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -27,8 +27,16 @@ spectre_exporter_ps_begin (SpectreExporter *exporter,
|
|||
const char *filename)
|
||||
{
|
||||
exporter->from = fopen (exporter->doc->filename, "r");
|
||||
if (!exporter->from)
|
||||
return SPECTRE_STATUS_EXPORTER_ERROR;
|
||||
|
||||
exporter->to = fopen (filename, "w");
|
||||
|
||||
if (!exporter->to) {
|
||||
fclose (exporter->from);
|
||||
exporter->from = NULL;
|
||||
return SPECTRE_STATUS_EXPORTER_ERROR;
|
||||
}
|
||||
|
||||
pscopyheaders (exporter->from, exporter->to, exporter->doc);
|
||||
|
||||
return SPECTRE_STATUS_SUCCESS;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_EXPORTER_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -61,7 +61,7 @@ critic_error_code (int code)
|
|||
const char *errors[] = { "", ERROR_NAMES };
|
||||
int x = (-1) * code;
|
||||
|
||||
if (x < sizeof (errors) / sizeof (const char*)) {
|
||||
if (x < (int) (sizeof (errors) / sizeof (const char*))) {
|
||||
fprintf (stderr, "%s %d\n", errors[x], code);
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -216,7 +216,7 @@ spectre_gs_send_page (SpectreGS *gs,
|
|||
if (doc->numpages > 0) {
|
||||
if (!spectre_gs_process (gs,
|
||||
doc->filename,
|
||||
0, 0,
|
||||
llx, lly,
|
||||
doc->pages[page_index].begin,
|
||||
doc->pages[page_index].end))
|
||||
return FALSE;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_GS_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_MACROS_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_PAGE_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_PRIVATE_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_RENDER_CONTEXT_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "spectre-status.h"
|
||||
|
@ -38,6 +38,8 @@ spectre_status_to_string (SpectreStatus status)
|
|||
return "render error";
|
||||
case SPECTRE_STATUS_EXPORTER_ERROR:
|
||||
return "exporter error";
|
||||
case SPECTRE_STATUS_SAVE_ERROR:
|
||||
return "save error";
|
||||
}
|
||||
|
||||
return "unknown error status";
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_STATUS_H
|
||||
|
@ -43,7 +43,9 @@ typedef enum _SpectreStatus {
|
|||
SPECTRE_STATUS_RENDER_ERROR /*! There has been a problem
|
||||
rendering the page */,
|
||||
SPECTRE_STATUS_EXPORTER_ERROR /*! There has been a problem
|
||||
exporting the document */
|
||||
exporting the document */,
|
||||
SPECTRE_STATUS_SAVE_ERROR /*! There has been a problem
|
||||
saving the document */
|
||||
} SpectreStatus;
|
||||
|
||||
/*! Gets a textual description of the given status
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "spectre-utils.h"
|
||||
|
||||
|
@ -48,3 +50,62 @@ _spectre_strdup_printf (const char *format, ...)
|
|||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char *
|
||||
_spectre_strdup (const char *str)
|
||||
{
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
len = strlen (str) + 1;
|
||||
|
||||
copy = malloc (len);
|
||||
if (!copy)
|
||||
return NULL;
|
||||
|
||||
memcpy (copy, str, len);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
#define TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
|
||||
int
|
||||
_spectre_strncasecmp (const char *s1,
|
||||
const char *s2,
|
||||
size_t n)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
while (n && *s1 && *s2) {
|
||||
n -= 1;
|
||||
c1 = (int)(unsigned char) TOLOWER (*s1);
|
||||
c2 = (int)(unsigned char) TOLOWER (*s2);
|
||||
if (c1 != c2)
|
||||
return (c1 - c2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (n) ? (((int) (unsigned char) *s1) - ((int) (unsigned char) *s2)) : 0;
|
||||
}
|
||||
|
||||
int
|
||||
_spectre_strcasecmp (const char *s1,
|
||||
const char *s2)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
while (*s1 && *s2) {
|
||||
c1 = (int)(unsigned char) TOLOWER (*s1);
|
||||
c2 = (int)(unsigned char) TOLOWER (*s2);
|
||||
if (c1 != c2)
|
||||
return (c1 - c2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (((int)(unsigned char) *s1) - ((int)(unsigned char) *s2));
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_UTILS_H
|
||||
|
@ -28,6 +28,12 @@
|
|||
SPECTRE_BEGIN_DECLS
|
||||
|
||||
char *_spectre_strdup_printf (const char *format, ...);
|
||||
char *_spectre_strdup (const char *str);
|
||||
int _spectre_strncasecmp (const char *s1,
|
||||
const char *s2,
|
||||
size_t n);
|
||||
int _spectre_strcasecmp (const char *s1,
|
||||
const char *s2);
|
||||
|
||||
SPECTRE_END_DECLS
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* 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.
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SPECTRE_H
|
||||
|
|
Loading…
Reference in a new issue