Exemple #1
0
/* Return pointer to View with same 'label', or null. */
View *
data_find(char*label) {
	Data	*d;
	Stat	buf;
	Path	path;

	/* Search for data with same label */
	for(d=dataroot; d; d=d->next) {
		if (STRSAME(d->label, label))
			return text_view(d->t);
	}

	/* Search for data with same stat buffer */
	label2path(path,label);
	if(stat(path,&buf))
		return 0;
	
	for(d=dataroot; d; d=d->next) {
		data_restat(d);
		if (d->has_stat && !statcmp(&buf, &d->stat))
			return text_view(d->t);
	}
	
	return 0;
}
Exemple #2
0
/*
 * matchkey - match a keyword to a list
 */
static int
matchkey(
	register char *word,
	register struct keyword *keys
	)
{
	for (;;) {
		if (keys->keytype == CONFIG_UNKNOWN) {
			return CONFIG_UNKNOWN;
		}
		if (STRSAME(word, keys->text))
			return keys->keytype;
		keys++;
	}
}
Exemple #3
0
/* D's label has been changed to 's',
 * update our internal structures.
 */
void
data_setlabel(Data*d, char *s) {
	assert(d);

	/* Just record the new label, only update
	 * other stuff on demand.
	 */
	strcpy(d->label, s);
	if(STRSAME(d->label, d->cachedlabel)) {
		if(!data_isdirty(d)) {
			tag_rmtool(d->tag, "Put");
		}
	} else {
		tag_addtool(d->tag, "Get");
		tag_addtool(d->tag, "Put");
	}
}
/*
 * Desc:      Prepares the decoder library for the imminent decoding of an
 *            image.  This function sets the type of the image format that
 *            the library is to decode, and whether the library should
 *            use temporary files when decoding the image.  Using
 *            temporary files means writing to disk which is slow.
 * Input:
 *            id:          thread id (offset into arrays at top of this file)
 *            image_type:  string of the image subtype e.g. "png", "jpeg"
 *            use_temp_file:
 *                         do we create a temporary file to store image data,
 *                         or can we use a pipe and avoid writing to disk
 * Output:
 *            None
 * Return:
 *            None
 * Exception:
 *            java.lang.InternalError if the image_type is unknown, or if
 *            a native error occurs.
 * Class:     vlc_net_content_image_ImageDecoder
 * Desc:
 * Method:    initDecoder
 * Signature: (ILjava/lang/String;Z)V
 */
JNIEXPORT void JNICALL
Java_vlc_net_content_image_ImageDecoder_initDecoder
(JNIEnv *env, jobject obj, jint id, jstring image_type, jboolean use_temp_file)
{
   int i = 0;
   int init_successful = JNI_FALSE;
   const char *str;
   char buf[100];
   char tmpname[L_tmpnam];
   Parameters params;
   int* fd;

   fd = fd_list[id];

   /* obtain a C representation of the java string */
   str = (*env)->GetStringUTFChars(env, image_type, 0);

   /* search for the given image type and if found, perform initialisation */
   do
   {
      if (STRSAME(str, available_types[i].type_string))
      {
         /* If there is something at this ID spot already, throw it away
          * and start again. */
         if(param_list[id])
            free(param_list[id]);

         param_list[id] = available_types[i].init_func();
         params = param_list[id];
         if (params != NULL)
         {
            init_successful = JNI_TRUE;
         }
         else
         {
            /* No memory?, hopefully we'll never see this */
            throw_exception(env, "java/lang/OutOfMemoryError", NULL);
         }
      }
      else
      {
         i++;
      }
   } while(!init_successful && (i<NUM_KNOWN_TYPES));

   /* ensure that the fptr is NULL */
   params->fptr = NULL;

   /* setup error message string */
   if (!init_successful)
      sprintf(buf, "Unknown file type: '%s'", str);

   /* release the java string now we are finished with it */
   (*env)->ReleaseStringUTFChars(env, image_type, str);

   /* throw exception */
   if (!init_successful)
      throw_exception(env, "java/lang/InternalError", buf);

   /* If using green threads under a *nix system, a blocking thread */
   /* will block the entire process.  For this reason we can not */
   /* safely use a pipe to transfer data incase the reading end of */
   /* the pipe blocks.  So we use a temporary file to store the */
   /* image data and read from that file */
   if (use_temp_file)
   {
      /* create a temporary file and open it for writing */
      for( ; ; )
      {
         /* generate a name */
         tmpnam(tmpname);

         /* ensure we create this file sucessfully */
         if ( (fd[1] = creat(tmpname, S_IREAD | S_IWRITE)) >= 0)
            break;
      }

      /* now open the temporary file for writing */
      params->fptr = fopen(tmpname, "rb");

      /* now unlink the file.  this will remove the file from */
      /* the directory, but will not reclaim disk space until */
      /* all descriptors referencing the file are closed */
      unlink(tmpname);
   }
   else
   {
      /* prepare for receiving data */
      if (pipe(fd) == -1)
      {
         /* throw exception */
         throw_exception(env, "java/lang/InternalError",
                         "Could not create pipe");
      }

      /* wrap a file pointer around the pipe descriptor */
      params->fptr = fdopen(fd[0], "rb");
   }

   /* ensure it worked */
   if (params->fptr == NULL)
      throw_exception(env, "java/lang/InternalError", "fdopen error");
}