-/*
- * open the given file to be read as an xpmData which is returned.
- */
-int
-xpmReadFile(char *filename, xpmData *mdata)
-{
-#ifdef ZPIPE
- char *compressfile, buf[BUFSIZ];
- struct stat status;
-
-#endif
-
- if (!filename) {
- mdata->stream.file = (stdin);
- mdata->type = XPMFILE;
- } else {
-#ifdef ZPIPE
- if (((int) strlen(filename) > 2) &&
- !strcmp(".Z", filename + (strlen(filename) - 2))) {
- mdata->type = XPMPIPE;
- sprintf(buf, "uncompress -c %s", filename);
- if (!(mdata->stream.file = popen(buf, "r")))
- return (XpmOpenFailed);
-
- } else if (((int) strlen(filename) > 3) &&
- !strcmp(".gz", filename + (strlen(filename) - 3))) {
- mdata->type = XPMPIPE;
- sprintf(buf, "gunzip -qc %s", filename);
- if (!(mdata->stream.file = popen(buf, "r")))
- return (XpmOpenFailed);
-
- } else {
- if (!(compressfile = (char *) XpmMalloc(strlen(filename) + 4)))
- return (XpmNoMemory);
-
- strcpy(compressfile, filename);
- strcat(compressfile, ".Z");
- if (!stat(compressfile, &status)) {
- sprintf(buf, "uncompress -c %s", compressfile);
- if (!(mdata->stream.file = popen(buf, "r"))) {
- XpmFree(compressfile);
- return (XpmOpenFailed);
- }
- mdata->type = XPMPIPE;
- } else {
- strcpy(compressfile, filename);
- strcat(compressfile, ".gz");
- if (!stat(compressfile, &status)) {
- sprintf(buf, "gunzip -c %s", compressfile);
- if (!(mdata->stream.file = popen(buf, "r"))) {
- XpmFree(compressfile);
- return (XpmOpenFailed);
- }
- mdata->type = XPMPIPE;
- } else {
-#endif
- if (!(mdata->stream.file = fopen(filename, "r"))) {
-#ifdef ZPIPE
- XpmFree(compressfile);
-#endif
- return (XpmOpenFailed);
- }
- mdata->type = XPMFILE;
-#ifdef ZPIPE
- }
- }
- XpmFree(compressfile);
- }
-#endif
- }
- mdata->CommentLength = 0;
- return (XpmSuccess);
-}
-
-/*
- * open the given file to be written as an xpmData which is returned
- */
-int
-xpmWriteFile(char *filename, xpmData *mdata)
-{
-#ifdef ZPIPE
- char buf[BUFSIZ];
-
-#endif
-
- if (!filename) {
- mdata->stream.file = (stdout);
- mdata->type = XPMFILE;
- } else {
-#ifdef ZPIPE
- if ((int) strlen(filename) > 2
- && !strcmp(".Z", filename + (strlen(filename) - 2))) {
- sprintf(buf, "compress > %s", filename);
- if (!(mdata->stream.file = popen(buf, "w")))
- return (XpmOpenFailed);
-
- mdata->type = XPMPIPE;
- } else if ((int) strlen(filename) > 3
- && !strcmp(".gz", filename + (strlen(filename) - 3))) {
- sprintf(buf, "gzip -q > %s", filename);
- if (!(mdata->stream.file = popen(buf, "w")))
- return (XpmOpenFailed);
-
- mdata->type = XPMPIPE;
- } else {
-#endif
- if (!(mdata->stream.file = fopen(filename, "w")))
- return (XpmOpenFailed);
-
- mdata->type = XPMFILE;
-#ifdef ZPIPE
- }
-#endif
- }
- return (XpmSuccess);
-}
-
-/*
- * open the given array to be read or written as an xpmData which is returned
- */
-void
-xpmOpenArray(char **data, xpmData *mdata)
-{
- mdata->type = XPMARRAY;
- mdata->stream.data = data;
- mdata->cptr = *data;
- mdata->line = 0;
- mdata->CommentLength = 0;
- mdata->Bcmt = mdata->Ecmt = NULL;
- mdata->Bos = mdata->Eos = '\0';
- mdata->format = 0; /* this can only be Xpm 2 or 3 */
-}
-
-/*
- * open the given buffer to be read or written as an xpmData which is returned
- */
-void
-xpmOpenBuffer(char *buffer, xpmData *mdata)
-{
- mdata->type = XPMBUFFER;
- mdata->cptr = buffer;
- mdata->CommentLength = 0;
-}
-
-/*
- * close the file related to the xpmData if any
- */
-int
-xpmDataClose(xpmData *mdata)
-{
- switch (mdata->type) {
- case XPMARRAY:
- case XPMBUFFER:
- break;
- case XPMFILE:
- if (mdata->stream.file != (stdout) && mdata->stream.file != (stdin))
- fclose(mdata->stream.file);
- break;
-#ifdef ZPIPE
- case XPMPIPE:
- pclose(mdata->stream.file);
- break;
-#endif
- }
- return 0;
-}
-