1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
//
// Copyright (C) 2001,2002,2003,2004 Jorge Daza Garcia-Blanes
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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
//
// $Id: bmrtsg.c 1141 2005-01-31 06:14:26Z kraken $
//
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include "bmrtsg.h"
#include "libdrqueue.h"
char *bmrtsg_create (struct bmrtsgi *info)
{
/* This function creates the bmrt render script based on the information given */
/* Returns a pointer to a string containing the path of the just created file */
/* Returns NULL on failure and sets drerrno */
FILE *f;
FILE *etc_bmrt_sg; /* The bmrt script generator configuration file */
int fd_etc_bmrt_sg,fd_f;
static char filename[BUFFERLEN];
char fn_etc_bmrt_sg[BUFFERLEN]; /* File name pointing to DRQUEUE_ETC/bmrt.sg */
char buf[BUFFERLEN];
int size;
char *p; /* Scene filename without path */
/* Check the parameters */
if (!strlen(info->scene)) {
drerrno = DRE_NOTCOMPLETE;
return NULL;
}
p = strrchr(info->scene,'/');
p = ( p ) ? p+1 : info->scene;
snprintf(filename,BUFFERLEN-1,"%s/%s.%lX",info->scriptdir,p,(unsigned long int)time(NULL));
if ((f = fopen (filename, "a")) == NULL) {
if (errno == ENOENT) {
/* If its because the directory does not exist we try creating it first */
if (mkdir (info->scriptdir,0775) == -1) {
drerrno = DRE_COULDNOTCREATE;
return NULL;
} else if ((f = fopen (filename, "a")) == NULL) {
drerrno = DRE_COULDNOTCREATE;
return NULL;
}
} else {
drerrno = DRE_COULDNOTCREATE;
return NULL;
}
}
fchmod (fileno(f),0777);
/* So now we have the file open and so we must write to it */
fprintf(f,"#!/bin/tcsh\n\n");
fprintf(f,"set SCENE=%s\n",info->scene);
fprintf(f,"set CUSTOM_CROP=%u\n",info->custom_crop);
if (info->custom_crop) {
fprintf(f,"set CROP_XMIN=%u\n",info->xmin);
fprintf(f,"set CROP_XMAX=%u\n",info->xmax);
fprintf(f,"set CROP_YMIN=%u\n",info->ymin);
fprintf(f,"set CROP_YMAX=%u\n",info->ymax);
}
fprintf(f,"set CUSTOM_SAMPLES=%u\n",info->custom_samples);
if (info->custom_samples) {
fprintf(f,"set XSAMPLES=%u\n",info->xsamples);
fprintf(f,"set YSAMPLES=%u\n",info->ysamples);
}
fprintf(f,"set DISP_STATS=%u\n",info->disp_stats);
fprintf(f,"set VERBOSE=%u\n",info->verbose);
fprintf(f,"set CUSTOM_BEEP=%u\n",info->custom_beep);
fprintf(f,"set CUSTOM_RADIOSITY=%u\n",info->custom_radiosity);
if (info->custom_radiosity) {
fprintf(f,"set RADIOSITY_SAMPLES=%u\n",info->radiosity_samples);
}
fprintf(f,"set CUSTOM_RAYSAMPLES=%u\n",info->custom_raysamples);
if (info->custom_raysamples) {
fprintf(f,"set RAYSAMPLES=%u\n",info->raysamples);
}
snprintf(fn_etc_bmrt_sg,BUFFERLEN-1,"%s/bmrt.sg",getenv("DRQUEUE_ETC"));
fflush (f);
if ((etc_bmrt_sg = fopen (fn_etc_bmrt_sg,"r")) == NULL) {
fprintf(f,"\necho -------------------------------------------------\n");
fprintf(f,"echo ATTENTION ! There was a problem opening: %s\n",fn_etc_bmrt_sg);
fprintf(f,"echo So the default configuration will be used\n");
fprintf(f,"echo -------------------------------------------------\n");
fprintf(f,"\n\n");
fprintf(f,"echo rendrib -frames $DRQUEUE_FRAME $BLOCK\n\n");
} else {
fd_etc_bmrt_sg = fileno (etc_bmrt_sg);
fd_f = fileno (f);
while ((size = read (fd_etc_bmrt_sg,buf,BUFFERLEN)) != 0) {
write (fd_f,buf,size);
}
fclose(etc_bmrt_sg);
}
fclose(f);
return filename;
}
char *bmrtsg_default_script_path (void)
{
static char buf[BUFFERLEN];
char *p;
if (!(p = getenv("DRQUEUE_TMP"))) {
return ("/drqueue_tmp/not/set/");
}
#ifdef __CYGWIN
if (p[strlen(p)-1] == '\\')
snprintf (buf,BUFFERLEN-1,"%s",p);
else
snprintf (buf,BUFFERLEN-1,"%s\\",p);
#else
if (p[strlen(p)-1] == '/')
snprintf (buf,BUFFERLEN-1,"%s",p);
else
snprintf (buf,BUFFERLEN-1,"%s/",p);
#endif
return buf;
}
|