コード例 #1
0
static void
gst_real_audio_dec_probe_modules (GstRealAudioDec * dec)
{
  GstRADecLibrary dummy = { NULL };

  if ((dec->valid_atrk =
          open_library (dec, GST_REAL_AUDIO_DEC_VERSION_ATRK, &dummy)))
    close_library (dec, &dummy);
  if ((dec->valid_ra14_4 =
          open_library (dec, GST_REAL_AUDIO_DEC_VERSION_14_4, &dummy)))
    close_library (dec, &dummy);
  if ((dec->valid_ra28_8 =
          open_library (dec, GST_REAL_AUDIO_DEC_VERSION_28_8, &dummy)))
    close_library (dec, &dummy);
#ifdef HAVE_CPU_X86_64
  /* disabled because it does not seem to work on 64 bits */
  dec->valid_sipr = FALSE;
#else
  if ((dec->valid_sipr =
          open_library (dec, GST_REAL_AUDIO_DEC_VERSION_SIPR, &dummy)))
    close_library (dec, &dummy);
#endif
  if ((dec->valid_cook =
          open_library (dec, GST_REAL_AUDIO_DEC_VERSION_COOK, &dummy)))
    close_library (dec, &dummy);
}
コード例 #2
0
ファイル: niepcewindow.cpp プロジェクト: GNOME/niepce
void NiepceWindow::on_open_library()
{
    Configuration & cfg = Application::app()->config();
    std::string libMoniker;
    int reopen = 0;
    try {
        reopen = std::stoi(cfg.getValue("reopen_last_catalog", "0"));
    }
    catch(...)
    {
    }
    if(reopen) {
        libMoniker = cfg.getValue("last_open_catalog", "");
    }
    if(libMoniker.empty()) {
        libMoniker = prompt_open_library();
    }
    else {
        DBG_OUT("last library is %s", libMoniker.c_str());
    }
    if(!libMoniker.empty()) {
        if(!open_library(libMoniker)) {
            ERR_OUT("library %s cannot be open. Prompting.",
                    libMoniker.c_str());
            libMoniker = prompt_open_library();
            open_library(libMoniker);
        }
    }
}
コード例 #3
0
ファイル: drew.c プロジェクト: bk2204/drew
/* Allocate a library table entry and load the library information from it.  If
 * library is NULL, try to load the current executable instead.
 */
static int load_library(DrewLoader *ldr, const char *library,
                        const char *path, library_t **libp)
{
    int err = 0;
    library_t *p, *lib;
    p = g_realloc(ldr->lib, sizeof(*p) * (ldr->nlibs + 1));
    if (!p)
        return -ENOMEM;
    if (p != ldr->lib) {
        // Fix up the lib pointers in the plugins.
        for (int i = 0; i < ldr->nplugins; i++)
            ldr->plugin[i].lib = p + (ldr->plugin[i].lib - ldr->lib);
    }
    ldr->lib = p;
    lib = &ldr->lib[ldr->nlibs];
    memset(lib, 0, sizeof(*lib));
    ldr->nlibs++;

    if (!library) {
        err = -DREW_ERR_RESOLUTION;
        if (!(lib->handle = open_library(NULL)))
            goto out;
        lib->name = g_strdup("<internal>");
        lib->path = NULL;
    }
    else {
        err = -ENOMEM;
        if (!(lib->path = g_strdup_printf("%s/%s", path, library)))
            goto out;
        // TODO: query this from the library.
        lib->name = g_strdup(library);
        err = -DREW_ERR_RESOLUTION;
        if (!(lib->handle = open_library(lib->path)))
            goto out;
    }
    err = -DREW_ERR_ENUMERATION;
    if (!(lib->api = get_api(lib->handle)))
        goto out;

    err = 0;
    *libp = lib;
out:
    if (err) {
        if (lib->handle)
            close_library(lib->handle);
        g_free(lib->name);
        g_free(lib->path);
        lib->path = NULL;
        ldr->nlibs--;
    }
    return err;
}
コード例 #4
0
/** Opens compress library of given name. */
static void *compress_open_library(const char *compress_name)
{
    char name[128];
    snprintf(name, sizeof(name), "vcompress_%s.so.%d", compress_name, VIDEO_COMPRESS_ABI_VERSION);

    return open_library(name);
}
コード例 #5
0
static void *vo_pp_open_library(const char *vidcap_name)
{
        char name[128];
        snprintf(name, sizeof(name), "vo_pp_%s.so.%d", vidcap_name, VO_PP_ABI_VERSION);

        return open_library(name);
}
コード例 #6
0
ファイル: uaenative.cpp プロジェクト: nekoniaow/WinUAE
uae_u32 uaenative_open_library (TrapContext *context, int flags)
{
    if (!currprefs.native_code) {
        write_log(_T("uni: tried to open native library, but native code ")
                  _T("is not enabled\n"));
        return UNI_ERROR_NOT_ENABLED;
    }

    uaecptr name;
    uae_u32 min_version;
    if (flags & UNI_FLAG_COMPAT) {
        name = m68k_areg (regs, 0);
        min_version = 0;
    }
    else {
        name = m68k_areg (regs, 1);
        min_version = m68k_dreg (regs, 0);
    }

    uae_u32 result = open_library (
        (const char *) get_real_address (name), min_version);

    if ((flags & UNI_FLAG_COMPAT) && !(result & 0x80000000)) {
        // error opening library, return 0 for error in compatibility mode
        return 0;
    }
    return result;
}
コード例 #7
0
ファイル: Collection.cpp プロジェクト: lindenle/QTpapers
void Collection::readSettings()
{
  QSettings settings("LindenLevy", "QtPapers");

  settings.beginGroup("Collection");
  resize(settings.value("size", QSize(700, 500)).toSize());
  move(settings.value("pos", QPoint(200, 200)).toPoint());
  _top_layout->restoreState(settings.value("middle").toByteArray());
  _bot_layout->restoreState(settings.value("middle_bot").toByteArray());
  _total_layout->restoreState(settings.value("total").toByteArray());
  settings.endGroup();

  settings.beginGroup("PaperList");
  _paper_list->setColumnWidth(0,settings.value("leftwidth", 50).toInt());
  _paper_list->setColumnWidth(1,settings.value("centerwidth", 50).toInt());
  settings.endGroup();

  settings.beginGroup("LastLibrary");

  QStringList files(settings.value("files","empty").toStringList());
  _stdout << "Size:" << files.size() << endl;
  if (  files.at(0) != "empty" )
    {
      QStringList::const_iterator iter=files.constBegin();
      
      for (; iter != files.constEnd(); ++iter)
	{
	  _stdout << "Opening" << *iter << endl;
	  open_library(*iter);
	}
    }
  settings.endGroup();
}
コード例 #8
0
static void *display_open_library(const char *display_name)
{
        char name[128];
        snprintf(name, sizeof(name), "display_%s.so.%d", display_name, VIDEO_DISPLAY_ABI_VERSION);

        return open_library(name);
}
コード例 #9
0
ファイル: dlb.c プロジェクト: ComputerScienceHouse/bingehack4
/*
 * Open the library file once using stdio.  Keep it open, but
 * keep track of the file position.
 */
static boolean
lib_dlb_init(void)
{
    /* zero out array */
    memset((char *)&dlb_libs[0], 0, sizeof (dlb_libs));

    /* To open more than one library, add open library calls here. */
    if (!open_library(DLBFILE, &dlb_libs[0]))
        return FALSE;
#ifdef DLBFILE2
    if (!open_library(DLBFILE2, &dlb_libs[1])) {
        close_library(&dlb_libs[0]);
        return FALSE;
    }
#endif
    return TRUE;
}
コード例 #10
0
ファイル: egldriver.c プロジェクト: MttDs/new-rexeno-tindpe
/**
 * Try to determine which EGL APIs (OpenGL, OpenGL ES, OpenVG, etc)
 * are supported on the system by looking for standard library names.
 */
EGLint
_eglFindAPIs(void)
{
   EGLint mask = 0x0;
   lib_handle lib;
#if defined(_EGL_PLATFORM_WINDOWS)
   /* XXX not sure about these names */
   const char *es1_libname = "libGLESv1_CM.dll";
   const char *es2_libname = "libGLESv2.dll";
   const char *gl_libname = "OpenGL32.dll";
   const char *vg_libname = "libOpenVG.dll";
#elif defined(_EGL_PLATFORM_X)
   const char *es1_libname = "libGLESv1_CM.so";
   const char *es2_libname = "libGLESv2.so";
   const char *gl_libname = "libGL.so";
   const char *vg_libname = "libOpenVG.so";
#else /* _EGL_PLATFORM_NO_OS */
   const char *es1_libname = NULL;
   const char *es2_libname = NULL;
   const char *gl_libname = NULL;
   const char *vg_libname = NULL;
#endif

   if ((lib = open_library(es1_libname))) {
      close_library(lib);
      mask |= EGL_OPENGL_ES_BIT;
   }

   if ((lib = open_library(es2_libname))) {
      close_library(lib);
      mask |= EGL_OPENGL_ES2_BIT;
   }

   if ((lib = open_library(gl_libname))) {
      close_library(lib);
      mask |= EGL_OPENGL_BIT;
   }

   if ((lib = open_library(vg_libname))) {
      close_library(lib);
      mask |= EGL_OPENVG_BIT;
   }

   return mask;
}
コード例 #11
0
ファイル: egldriver.c プロジェクト: MttDs/new-rexeno-tindpe
/**
 * Open the named driver and find its bootstrap function: _eglMain().
 */
static _EGLMain_t
_eglOpenLibrary(const char *driverPath, lib_handle *handle)
{
   lib_handle lib;
   _EGLMain_t mainFunc = NULL;
   const char *error = "unknown error";

   assert(driverPath);

   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
   lib = open_library(driverPath);

#if defined(_EGL_PLATFORM_WINDOWS)
   /* XXX untested */
   if (lib)
      mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
#elif defined(_EGL_PLATFORM_X)
   if (lib) {
      mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
      if (!mainFunc)
         error = dlerror();
   }
   else {
      error = dlerror();
   }
#else /* _EGL_PLATFORM_NO_OS */
   /* must be the default driver name */
   if (strcmp(driverPath, DefaultDriverName) == 0)
      mainFunc = (_EGLMain_t) _eglMain;
   else
      error = "not builtin driver";
#endif

   if (!lib) {
      _eglLog(_EGL_WARNING, "Could not open driver %s (%s)",
              driverPath, error);
      if (!getenv("EGL_DRIVER"))
         _eglLog(_EGL_WARNING,
                 "The driver can be overridden by setting EGL_DRIVER");
      return NULL;
   }

   if (!mainFunc) {
      _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)",
              driverPath, error);
      if (lib)
         close_library(lib);
      return NULL;
   }

   *handle = lib;
   return mainFunc;
}
コード例 #12
0
/**
 * Open the named driver and find its bootstrap function: _eglMain().
 */
static _EGLMain_t
_eglOpenLibrary(const char *driverPath, lib_handle *handle)
{
   lib_handle lib;
   _EGLMain_t mainFunc = NULL;
   const char *error = "unknown error";

   assert(driverPath);

   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
   lib = open_library(driverPath);

#if defined(_EGL_OS_WINDOWS)
   /* XXX untested */
   if (lib)
      mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
#elif defined(_EGL_OS_UNIX)
   if (lib) {
      union {
         _EGLMain_t func;
         void *ptr;
      } tmp = { NULL };
      /* direct cast gives a warning when compiled with -pedantic */
      tmp.ptr = dlsym(lib, "_eglMain");
      mainFunc = tmp.func;
      if (!mainFunc)
         error = dlerror();
   }
   else {
      error = dlerror();
   }
#endif

   if (!lib) {
      _eglLog(_EGL_WARNING, "Could not open driver %s (%s)",
              driverPath, error);
      if (!getenv("EGL_DRIVER"))
         _eglLog(_EGL_WARNING,
                 "The driver can be overridden by setting EGL_DRIVER");
      return NULL;
   }

   if (!mainFunc) {
      _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)",
              driverPath, error);
      if (lib)
         close_library(lib);
      return NULL;
   }

   *handle = lib;
   return mainFunc;
}
コード例 #13
0
ファイル: Collection.cpp プロジェクト: lindenle/QTpapers
void Collection::open_library()
{
  
  QFileDialog dialog(this);
  dialog.setFileMode(QFileDialog::ExistingFile);
  dialog.setViewMode(QFileDialog::Detail);
  dialog.hasFocus();
  dialog.show();
  if (dialog.exec())
    {
      open_library(dialog.selectedFiles().at(0));
    }
}
コード例 #14
0
ファイル: import.c プロジェクト: NVIDIA/winex_lgpl
/* read in the list of exported symbols of a .so */
static void read_exported_symbols( const char *name, struct import *imp )
{
    FILE *f;
    char buffer[1024];
    char *fullname, *cmdline;
    const char *ext;
    int size, err;

    imp->exports    = NULL;
    imp->nb_exports = size = 0;

    if (!(ext = strrchr( name, '.' ))) ext = name + strlen(name);

    if (!(fullname = open_library( name ))) return;
    cmdline = xmalloc( strlen(fullname) + 7 );
#if !defined(__APPLE__)    
    sprintf( cmdline, "nm -D %s", fullname );
#else
    /* MacOS X does not support the -D commandline option */
    sprintf( cmdline, "nm %s", fullname);
#endif
    free( fullname );

    if (!(f = popen( cmdline, "r" )))
        fatal_error( "Cannot execute '%s'\n", cmdline );

    while (fgets( buffer, sizeof(buffer), f ))
    {
        char *p = buffer + strlen(buffer) - 1;
        if (p < buffer) continue;
        if (*p == '\n') *p-- = 0;
        if (!(p = strstr( buffer, "__wine_dllexport_" ))) continue;
        p += 17;
        if (strncmp( p, name, ext - name )) continue;
        p += ext - name;
        if (*p++ != '_') continue;

        if (imp->nb_exports == size)
        {
            size += 128;
            imp->exports = xrealloc( imp->exports, size * sizeof(*imp->exports) );
        }
        imp->exports[imp->nb_exports++] = xstrdup( p );
    }
    if ((err = pclose( f ))) fatal_error( "%s error %d\n", cmdline, err );
    free( cmdline );
    sort_symbols( imp->exports, imp->nb_exports );
}
コード例 #15
0
ファイル: makebootstrap.c プロジェクト: AOSC-Dev/metahtml
static void
dump_library (char *filename)
{
  int fd = os_open (filename, O_RDONLY, 0666);

  open_library ();	/* Open the output lib if not already opened. */

  if (fd > -1)
    {
      struct stat finfo;

      if (stat (filename, &finfo) != -1)
	{
	  char *buffer = (char *)malloc (1 + (int)finfo.st_size);
	  register int i;
	  int chars_this_line = 0;

	  read (fd, buffer, (size_t)finfo.st_size);

	  for (i = 0; i < finfo.st_size; i++)
	    {
	      /* Start a new line if that is the right thing. */

	      if (!chars_this_line)
		fprintf (stdout, "\n  ");

	      fprintf (stdout, "'\\%03o', ", (unsigned char)buffer[i]);

	      chars_this_line++;
	      if (chars_this_line == 9)
		{
		  fprintf (stdout, "\n");
		  chars_this_line = 0;
		}
	    }

	  free (buffer);
	  bootstrap_code_len += i;
	}
    }
}
コード例 #16
0
static gboolean
gst_real_audio_dec_setcaps (GstPad * pad, GstCaps * caps)
{
  GstRealAudioDec *dec = GST_REAL_AUDIO_DEC (GST_PAD_PARENT (pad));
  GstStructure *s = gst_caps_get_structure (caps, 0);
  gint version, flavor, channels, rate, leaf_size, packet_size, width, height;
  guint16 res = 0;
  RAInit data;
  gboolean bres;
  const GValue *v;
  GstBuffer *buf = NULL;
  const gchar *name = gst_structure_get_name (s);

  if (!strcmp (name, "audio/x-sipro")) {
    version = GST_REAL_AUDIO_DEC_VERSION_SIPR;
  } else {
    if (!gst_structure_get_int (s, "raversion", &version))
      goto missing_keys;
  }

  if (!gst_structure_get_int (s, "flavor", &flavor) ||
      !gst_structure_get_int (s, "channels", &channels) ||
      !gst_structure_get_int (s, "width", &width) ||
      !gst_structure_get_int (s, "rate", &rate) ||
      !gst_structure_get_int (s, "height", &height) ||
      !gst_structure_get_int (s, "leaf_size", &leaf_size) ||
      !gst_structure_get_int (s, "packet_size", &packet_size))
    goto missing_keys;

  if ((v = gst_structure_get_value (s, "codec_data")))
    buf = g_value_peek_pointer (v);

  GST_LOG_OBJECT (dec, "opening code for version %d", version);

  /* first close existing decoder */
  close_library (dec, &dec->lib);

  if (!open_library (dec, version, &dec->lib))
    goto could_not_open;

  /* we have the module, no initialize with the caps data */
  data.samplerate = rate;
  data.width = width;
  data.channels = channels;
  data.quality = 100;
  data.leaf_size = leaf_size;
  data.packet_size = packet_size;
  data.datalen = buf ? GST_BUFFER_SIZE (buf) : 0;
  data.data = buf ? GST_BUFFER_DATA (buf) : NULL;

  if ((res = dec->lib.RAInitDecoder (dec->lib.context, &data))) {
    GST_WARNING_OBJECT (dec, "RAInitDecoder() failed");
    goto could_not_initialize;
  }

  if (dec->lib.RASetPwd) {
    dec->lib.RASetPwd (dec->lib.context, dec->pwd ? dec->pwd : DEFAULT_PWD);
  }

  if ((res = dec->lib.RASetFlavor (dec->lib.context, flavor))) {
    GST_WARNING_OBJECT (dec, "RASetFlavor(%d) failed", flavor);
    goto could_not_initialize;
  }

  caps = gst_caps_new_simple ("audio/x-raw-int",
      "endianness", G_TYPE_INT, G_BYTE_ORDER,
      "width", G_TYPE_INT, width,
      "depth", G_TYPE_INT, width,
      "rate", G_TYPE_INT, rate,
      "channels", G_TYPE_INT, channels, "signed", G_TYPE_BOOLEAN, TRUE, NULL);
  bres = gst_pad_set_caps (GST_PAD (dec->src), caps);
  gst_caps_unref (caps);
  if (!bres)
    goto could_not_set_caps;

  dec->width = width;
  dec->height = height;
  dec->leaf_size = leaf_size;

  GST_LOG_OBJECT (dec, "opened module");

  return TRUE;

missing_keys:
  {
    GST_DEBUG_OBJECT (dec, "Could not find all necessary keys in structure.");
    return FALSE;
  }
could_not_open:
  {
    GST_DEBUG_OBJECT (dec, "Could not find decoder");
    return FALSE;
  }
could_not_initialize:
  {
    close_library (dec, &dec->lib);
    GST_WARNING_OBJECT (dec, "Initialization of REAL driver failed (%i).", res);
    return FALSE;
  }
could_not_set_caps:
  {
    /* should normally not fail */
    close_library (dec, &dec->lib);
    GST_DEBUG_OBJECT (dec, "Could not convince peer to accept caps.");
    return FALSE;
  }
}
コード例 #17
0
static gboolean
gst_real_video_dec_setcaps (GstPad * pad, GstCaps * caps)
{
  GstRealVideoDec *dec = GST_REAL_VIDEO_DEC (GST_PAD_PARENT (pad));
  GstStructure *s = gst_caps_get_structure (caps, 0);
  gint version, res, width, height, format, subformat;
  gint framerate_num, framerate_denom;
  gchar data[36];
  gboolean bres;
  const GValue *v;

  if (!gst_structure_get_int (s, "rmversion", &version) ||
      !gst_structure_get_int (s, "width", (gint *) & width) ||
      !gst_structure_get_int (s, "height", (gint *) & height) ||
      !gst_structure_get_int (s, "format", &format) ||
      !gst_structure_get_int (s, "subformat", &subformat) ||
      !gst_structure_get_fraction (s, "framerate", &framerate_num,
          &framerate_denom))
    goto missing_keys;

  GST_LOG_OBJECT (dec, "Setting version to %d", version);

  close_library (dec, &dec->lib);

  if (!open_library (dec, version, &dec->lib))
    goto open_failed;

  /* Initialize REAL driver. */
  GST_WRITE_UINT16_LE (data + 0, 11);
  GST_WRITE_UINT16_LE (data + 2, width);
  GST_WRITE_UINT16_LE (data + 4, height);
  GST_WRITE_UINT16_LE (data + 6, 0);
  GST_WRITE_UINT32_LE (data + 8, 0);
  GST_WRITE_UINT32_LE (data + 12, subformat);
  GST_WRITE_UINT32_LE (data + 16, 1);
  GST_WRITE_UINT32_LE (data + 20, format);

  if ((res = dec->lib.Init (&data, &dec->lib.context)))
    goto could_not_initialize;

  if ((v = gst_structure_get_value (s, "codec_data"))) {
    GstBuffer *buf;
    guint32 *msgdata;
    guint i;
    guint8 *bufdata;
    guint bufsize;
    struct
    {
      guint32 type;
      guint32 msg;
      gpointer data;
      guint32 extra[6];
    } msg;

    buf = g_value_peek_pointer (v);

    bufdata = GST_BUFFER_DATA (buf);
    bufsize = GST_BUFFER_SIZE (buf);

    /* skip format and subformat */
    bufdata += 8;
    bufsize -= 8;

    GST_LOG_OBJECT (dec, "Creating custom message of length %d", bufsize);

    msgdata = g_new0 (guint32, bufsize + 2);
    if (!msgdata)
      goto could_not_allocate;

    msg.type = 0x24;
    msg.msg = 1 + ((subformat >> 16) & 7);
    msg.data = msgdata;
    for (i = 0; i < 6; i++)
      msg.extra[i] = 0;
    msgdata[0] = width;
    msgdata[1] = height;
    for (i = 0; i < bufsize; i++)
      msgdata[i + 2] = 4 * (guint32) bufdata[i];

    res = dec->lib.Message (&msg, dec->lib.context);

    g_free (msgdata);
    if (res)
      goto could_not_send_message;
  }
コード例 #18
0
ファイル: dlb_main.c プロジェクト: ictxiangxin/LoongHack
int main(int argc, char *argv[])
{
    int i, r;
    int ap=2;				/* argument pointer */
    int cp;				/* command pointer */
    int iseen=0, fseen=0, verbose=0;	/* flags */
    char action=' ';
    library lib;

    if (argc > 0 && argv[0] && *argv[0]) progname = argv[0];

    if (argc<2) {
	usage();
	/* doesn't return */
    }

    for (cp=0; argv[1][cp]; cp++){
	switch(argv[1][cp]){
	    default:
		usage();	/* doesn't return */
	    case '-':	/* silently ignore */
		break;
	    case '?':
	    case 'h':
		verbose_help();
		break;
	    case 'I':
		if (ap == argc) usage();
		list_file=argv[ap++];
		if (iseen)
		    printf("Warning: multiple I options.  Previous ignored.\n");
		iseen=1;
		break;
	    case 'f':
		if (ap == argc) usage();
		library_file=argv[ap++];
		if (fseen)
		    printf("Warning: multiple f options.  Previous ignored.\n");
		fseen=1;
		break;
	    case 'C':
		if (ap == argc) usage();
		if (chdir(argv[ap++])){
		    printf("Can't chdir to %s\n",argv[--ap]);
		    xexit(EXIT_FAILURE);
		}
		break;
	    case 'v':
		verbose=1;
		break;
	    case 't':
	    case 'c':
	    case 'x':
		if (action != ' '){
		    printf("Only one of t,x,c may be specified.\n");
		    usage();
		}
		action=argv[1][cp];
		break;
	}
    }

    if (argv[ap] && iseen){
	printf("Too many arguments.\n");
	xexit(EXIT_FAILURE);
    }

    switch(action){
    default:
	printf("Internal error - action.\n");
	xexit(EXIT_FAILURE);
	break;
    case 't':			/* list archive */
	if (!open_library(library_file, &lib)) {
	    printf("Can't open dlb file\n");
	    xexit(EXIT_FAILURE);
	}

	for (i = 0; i < lib.nentries; i++) {
	    if (verbose)
		printf("%-14s %6ld %6ld\n",
		    lib.dir[i].fname, lib.dir[i].foffset, lib.dir[i].fsize);
	    else
		printf("%s\n", lib.dir[i].fname);
	}

	if (verbose)
	    printf("Revision:%ld  File count:%ld  String size:%ld\n",
		lib.rev, lib.nentries, lib.strsize);

	close_library(&lib);
	xexit(EXIT_SUCCESS);

    case 'x': {			/* extract archive contents */
	int f, n;
	long remainder, total_read;
	char buf[BUFSIZ];

	if (!open_library(library_file, &lib)) {
	    printf("Can't open dlb file\n");
	    xexit(EXIT_FAILURE);
	}

	for (i = 0; i < lib.nentries; i++) {
	    if (argv[ap]) {
		/* if files are listed, see if current is wanted */
		int c;
		for (c = ap; c < argc; c++)
		    if (!FILENAME_CMP(lib.dir[i].fname, argv[c])) break;
		if (c == argc) continue;	/* skip */
	    } else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) {
		/*
		 * Don't extract the directory unless the user
		 * specifically asks for it.
		 *
		 * Perhaps we should never extract the directory???
		 */
		continue;
	    }
	    fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET);

	    f = open(lib.dir[i].fname, O_WRONLY|O_TRUNC|O_BINARY|O_CREAT, 0640);
	    if (f < 0) {
		printf("Can't create '%s'\n", lib.dir[i].fname);
		xexit(EXIT_FAILURE);
	    }

	    /* read chunks from library and write them out */
	    total_read = 0;
	    do {
		remainder = lib.dir[i].fsize - total_read;
		if (remainder > (long) sizeof(buf))
		    r = (int) sizeof(buf);
		else
		    r = remainder;

		n = fread(buf, 1, r, lib.fdata);
		if (n != r) {
		    printf("Read Error in '%s'\n", lib.dir[i].fname);
		    xexit(EXIT_FAILURE);
		}
		if (write(f, buf, n) != n) {
		    printf("Write Error in '%s'\n", lib.dir[i].fname);
		    xexit(EXIT_FAILURE);
		}

		total_read += n;
	    } while (total_read != lib.dir[i].fsize);

	    close(f);

	    if (verbose) printf("x %s\n", lib.dir[i].fname);
	}

	close_library(&lib);
	xexit(EXIT_SUCCESS);
	}

    case 'c':			/* create archive */
	{
	libdir ld[MAX_DLB_FILES];
	char buf[BUFSIZ];
	int fd, out, nfiles = 0;
	long dir_size, slen, flen, fsiz;
	boolean rewrite_directory = FALSE;

	/*
	 * Get names from either/both an argv list and a file
	 * list.  This does not do any duplicate checking
	 */

	/* get file name in argv list */
	if (argv[ap]) {
	    for ( ; ap < argc; ap++, nfiles++) {
		if (nfiles >= MAX_DLB_FILES) {
		    printf("Too many dlb files!  Stopping at %d.\n",
								MAX_DLB_FILES);
		    xexit(EXIT_FAILURE);
		}
		ld[nfiles].fname = malloc(strlen(argv[ap]) + 1);
		strcpy(ld[nfiles].fname, argv[ap]);
	    }
	}

	if (iseen) {
	    /* want to do a list file */
	    FILE *list = fopen(list_file, "r");
	    if (!list) {
		printf("Can't open %s\n",list_file);
		xexit(EXIT_FAILURE);
	    }

	    /* get file names, one per line */
	    for ( ; fgets(buf, sizeof(buf), list); nfiles++) {
		if (nfiles >= MAX_DLB_FILES) {
		    printf("Too many dlb files!  Stopping at %d.\n",
								MAX_DLB_FILES);
		    xexit(EXIT_FAILURE);
		}
		*(eos(buf)-1) = '\0';	/* strip newline */
		ld[nfiles].fname = malloc(strlen(buf) + 1);
		strcpy(ld[nfiles].fname, buf);
	    }
	    fclose(list);
	}

	if (nfiles == 0) {
	    printf("No files to archive\n");
	    xexit(EXIT_FAILURE);
	}


	/*
	 * Get file sizes and name string length.  Don't include
	 * the directory information yet.
	 */
	for (i = 0, slen = 0, flen = 0; i < nfiles; i++) {
	    fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0);
	    if (fd < 0) {
		printf("Can't open %s\n", ld[i].fname);
		xexit(EXIT_FAILURE);
	    }
	    ld[i].fsize = lseek(fd, 0, SEEK_END);
	    ld[i].foffset = flen;

	    slen += strlen(ld[i].fname);	/* don't add null (yet) */
	    flen += ld[i].fsize;
	    close(fd);
	}

	/* open output file */
	out = open(library_file, O_RDWR|O_TRUNC|O_BINARY|O_CREAT, FCMASK);
	if (out < 0) {
	    printf("Can't open %s for output\n", library_file);
	    xexit(EXIT_FAILURE);
	}

	/* caculate directory size */
	dir_size = 40			/* header line (see below) */
		   + ((nfiles+1)*11)	/* handling+file offset+SP+newline */
		   + slen+strlen(DLB_DIRECTORY); /* file names */

	/* write directory */
	write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);

	flen = 0L;
	/* write each file */
	for (i = 0; i < nfiles; i++) {
	    fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0);
	    if (fd < 0) {
		printf("Can't open input file '%s'\n", ld[i].fname);
		xexit(EXIT_FAILURE);
	    }
	    if (verbose) printf("%s\n",ld[i].fname);

	    fsiz = 0L;
	    while ((r = read(fd, buf, sizeof buf)) != 0) {
		if (r == -1) {
		    printf("Read Error in '%s'\n", ld[i].fname);
		    xexit(EXIT_FAILURE);
		}
		if (write(out, buf, r) != r) {
		    printf("Write Error in '%s'\n", ld[i].fname);
		    xexit(EXIT_FAILURE);
		}
		fsiz += r;
	    }
	    close(fd);
	    if (fsiz != ld[i].fsize) rewrite_directory = TRUE;
	    /* in case directory rewrite is needed */
	    ld[i].fsize = fsiz;
	    ld[i].foffset = flen;
	    flen += fsiz;
	}

	if (rewrite_directory) {
	    if (verbose) printf("(rewriting dlb directory info)\n");
	    lseek(out, 0, SEEK_SET);	/* rewind */
	    write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);
	}

	for (i = 0; i < nfiles; i++)
	    free(ld[i].fname),  ld[i].fname = 0;

	close(out);
	xexit(EXIT_SUCCESS);
	}
    }

    xexit(EXIT_SUCCESS);
    /*NOTREACHED*/
    return 0;
}
コード例 #19
-1
ファイル: Collection.cpp プロジェクト: lindenle/QTpapers
Collection::Collection() :
  _current_library(0),
  _stdout(stdout)
{

  actionGroup = new QActionGroup(this);

  statusBar();

  QWidget::setWindowTitle( "Qt Papers" );

  QMenu* fileMenu = new QMenu("&File", this);    

  libraryOpen = addChoice("libraryOpen", "Open Library");
  libraryOpen->setStatusTip("Open a library");
  libraryOpen->setEnabled(true);
  libraryOpen->setIcon(QIcon(":/images/libopen.png"));
  connect(libraryOpen, SIGNAL(triggered()), this, SLOT(open_library()));
  fileMenu->addAction(libraryOpen);

  libraryNew = addChoice("libraryNew", "New Library");
  libraryNew->setStatusTip("Create a new library");
  libraryNew->setEnabled(true);
  libraryNew->setIcon(QIcon(":/images/document2.png"));
  connect(libraryNew, SIGNAL(triggered()), this, SLOT(new_library()));
  fileMenu->addAction(libraryNew);


  librarySave = addChoice("librarySave", "Save Library");
  librarySave->setStatusTip("Save the library");
  librarySave->setEnabled(true);
  librarySave->setIcon(QIcon(":/images/save.png"));
  connect(librarySave, SIGNAL(triggered()), this, SLOT(save_library()));
  fileMenu->addAction(librarySave);

  libraryDelete = addChoice("libraryDelete", "Delete Library");
  libraryDelete->setStatusTip("Delete library");
  libraryDelete->setEnabled(true);
  libraryDelete->setIcon(QIcon(":/images/libremove.png"));
  connect(libraryDelete, SIGNAL(triggered()), this, SLOT(delete_library()));
  fileMenu->addAction(libraryDelete);

  libraryImport = addChoice("libraryImport", "Import Library");
  libraryImport->setStatusTip("Import library");
  libraryImport->setEnabled(true);
  libraryImport->setIcon(QIcon(":/images/import.png"));
  connect(libraryImport, SIGNAL(triggered()), this, SLOT(scan_directory_and_import_papers()));

  fileMenu->addAction(libraryImport);

  preferences = addChoice("preferences", "Preferences");
  preferences->setStatusTip("Preferences");
  preferences->setEnabled(true);
  preferences->setIcon(QIcon(":/images/pref.png"));
  connect(preferences, SIGNAL(triggered()), this, SLOT(modify_preferences()));
  fileMenu->addAction(preferences);
  
  exit = addChoice("exit", "Exit");
  exit->setStatusTip("Exit");
  exit->setEnabled(true);
  exit->setIcon(QIcon(":/images/exit.png"));
  connect(exit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
  fileMenu->addAction(exit);

  QMenu* paperMenu = new QMenu("&Paper", this);    
  paperImport = addChoice("paperImport", "Import Paper");
  paperImport->setStatusTip("Import a paper");
  paperImport->setEnabled(false);
  paperImport->setIcon(QIcon(":/images/import.png"));

  paperScanDirectory = addChoice("paperScanDirectory", "Paper Scan");
  paperScanDirectory->setIcon(QIcon(":/images/scan.png"));
  paperScanDirectory->setStatusTip("Scan for papers.");
  paperScanDirectory->setEnabled(true);

  talkImport = addChoice("talkImport", "Import Talk");
  talkImport->setStatusTip("Import a talk");
  talkImport->setEnabled(false);

  paperNew = addChoice("paperNew", "New Paper");
  paperNew->setStatusTip("New paper");
  paperNew->setEnabled(true);
  paperNew->setIcon(QIcon(":/images/new.png"));

  paperDelete = addChoice("paperDelete", "Delete Paper");
  paperDelete->setStatusTip("Delete paper");
  paperDelete->setIcon(QIcon(":/images/remove.png"));
  paperDelete->setEnabled(false);

  paperEdit = addChoice("paperEdit", "Edit Paper");
  paperEdit->setStatusTip("Edit paper");
  paperEdit->setEnabled(false);
  paperEdit->setIcon(QIcon(":/images/edit.png"));

  paperOpen = addChoice("paperOpen", "Open Paper");
  paperOpen->setStatusTip("Open paper");
  paperOpen->setEnabled(false);
  paperOpen->setIcon(QIcon(":/images/open.png"));

  talkNew = addChoice("talkNew", "New Talk");
  talkNew->setStatusTip("New talk");
  talkNew->setEnabled(false);

  connect(paperNew, SIGNAL(triggered()), this, SLOT(new_paper()));
  connect(paperEdit, SIGNAL(triggered()), this, SLOT(edit_paper()));
  connect(paperDelete, SIGNAL(triggered()), this, SLOT(delete_paper()));
  connect(paperOpen, SIGNAL(triggered()), this, SLOT(open_paper()));
  connect(paperImport, SIGNAL(triggered()), this, SLOT(import_paper()));
  // need to implement this

  paperMenu->addAction(paperNew);
  paperMenu->addAction(paperImport);
  paperMenu->addAction(paperEdit);
  paperMenu->addAction(paperDelete);
  paperMenu->addAction(paperOpen);
  paperMenu->addAction(paperScanDirectory);
  paperMenu->addAction(talkNew);
  paperMenu->addAction(talkImport);




  QMenu* helpMenu = new QMenu("&Help", this);    
  showAbout = addChoice("showAbout","About");
  showAbout->setStatusTip("About");
  showAbout->setEnabled(true);
  showAbout->setIcon(QIcon(":/images/about.png"));
  connect(showAbout, SIGNAL(triggered()), this, SLOT(about()));
  helpMenu->addAction(showAbout);

  //Add a menu bar
  menuBar()->addMenu(fileMenu);
  menuBar()->addMenu(paperMenu);
  menuBar()->addMenu(helpMenu);

  //button to trigger find box
  paperFind = new QAction("Find Paper",this);
  paperFind->setStatusTip("Find paper");
  paperFind->setEnabled(true);
  paperFind->setIcon(QIcon(":/images/find.png"));
  connect(paperFind, SIGNAL(triggered()), this, SLOT(find_paper()));

  //add a tool bar
  QPushButton * find_clear = new QPushButton();
  find_clear->setStatusTip("Find paper");
  find_clear->setEnabled(true);
  find_clear->setIcon(QIcon(":/images/clear.png"));
  connect(find_clear, SIGNAL(clicked()), this, SLOT(reset_find()));

  QLabel * find = new QLabel();
  find->setText("Find: ");
  find->setLayoutDirection(Qt::LeftToRight);
  QLabel * in = new QLabel();
  in->setText(" in ");
  _find_edit = new QLineEdit;
  _find_edit->setFixedSize(_find_edit->sizeHint());
  _find_edit->setLayoutDirection(Qt::LeftToRight);
  connect(_find_edit, SIGNAL(returnPressed()), this, SLOT(find_paper()));

  _find_type = new QComboBox();
  QStringList find_names;
  find_names << "Author" << "Title" << "Abstract" << "Any";
  _find_type->insertItems(0,find_names);
  _find_type->setLayoutDirection(Qt::LeftToRight);
  find->setBuddy(_find_edit);
  paperToolBar = addToolBar(tr("Paper"));
  paperToolBar->setLayoutDirection(Qt::RightToLeft);
  paperToolBar->addAction(paperFind);
  paperToolBar->addWidget(_find_type);
  paperToolBar->addWidget(in);
  paperToolBar->addWidget(find_clear);
  paperToolBar->addWidget(_find_edit);
  paperToolBar->addWidget(find);
  paperToolBar->addAction(paperDelete);
  paperToolBar->addAction(paperEdit);
  paperToolBar->addAction(paperNew);
  paperToolBar->addAction(paperOpen);
  paperToolBar->addAction(paperImport);
  paperToolBar->addAction(paperScanDirectory);

  _rss_box = new RssWidget;
  connect(_rss_box, SIGNAL(urlChanged(const QUrl& )), 
	  this, SLOT(check_url(const QUrl& )));

  QAction * rssForward  = new QAction("rssForward",this);
  rssForward->setStatusTip("Forward");
  rssForward->setEnabled(true);
  rssForward->setIcon(QIcon(":/images/forward.png"));
  connect(rssForward, SIGNAL(triggered()), _rss_box, SLOT(forward()));
  paperToolBar->addAction(rssForward);

  QAction * rssBack  = new QAction("rssBack",this);
  rssBack->setStatusTip("Back");
  rssBack->setEnabled(true);
  rssBack->setIcon(QIcon(":/images/back.png"));
  connect(rssBack, SIGNAL(triggered()), _rss_box, SLOT(back()));
  paperToolBar->addAction(rssBack);

  //Set up a central widget that will have a layout in it

  _library_list = new LibraryList(this,this);
  QFont font;
  font.setBold(true);
  font.setCapitalization(QFont::SmallCaps);
  _library_list->setFont(font);
  connect(_library_list, SIGNAL(itemClicked( QListWidgetItem *)), this, SLOT(select_library(QListWidgetItem *)));
  
  
  _abstract_box = new QTextBrowser();
  _abstract_box->setAlignment(Qt::AlignJustify);
  _abstract_box->setFontWeight(QFont::DemiBold);
  _abstract_box->setPlainText("No Paper Selected");
  _paper_list = new PaperList(this,this);

  QStringList sl;
  // The following seems like a non-intuitive operator
  // overload but that is how they do it...
  sl << "Author" << "Title" << "Date";
  _paper_list->setColumnCount(3);
  _paper_list->setHorizontalHeaderLabels(sl);
  _paper_list->setAlternatingRowColors(true);
  _paper_list->horizontalHeader()->setStretchLastSection(true);
  _paper_list->verticalHeader()->hide();
  //  _paper_list->setSortingEnabled(true);
  //need to make the paper_list its own class for drag and drop
  //  _paper_list->setAcceptDrops(true);

  connect(_paper_list, SIGNAL(cellClicked(int , int )), 
	  this, SLOT(select_paper(int, int)));
  //  update_paper_list();
  

  _top_layout = new QSplitter();  
  _top_layout->addWidget(_library_list);
  _top_layout->addWidget(_paper_list);
  _top_layout->setStretchFactor(0,1);
  _top_layout->setStretchFactor(1,3);
  _top_layout->setContentsMargins(0,0,5,0);
  _top_layout->setOrientation(Qt::Horizontal);

  _bot_layout = new QSplitter();  
  _bot_layout->addWidget(_abstract_box);
  _bot_layout->addWidget(_rss_box);
  _bot_layout->setContentsMargins(0,0,0,0);
  _bot_layout->setStretchFactor(0,1);
  _bot_layout->setStretchFactor(1,3);
  _bot_layout->setOrientation(Qt::Horizontal);

  _total_layout = new QSplitter();
  _total_layout->addWidget(_top_layout);
  _total_layout->addWidget(_bot_layout);
  _total_layout->setStretchFactor(0,1);
  _total_layout->setStretchFactor(1,3);
  _total_layout->setOrientation(Qt::Vertical);

  //this splitter window is my central widget
  setCentralWidget(_total_layout);


  QPalette  palette;
  palette.setColor(QPalette::Background,Qt::white);
  centralWidget()->setPalette(palette);
  centralWidget()->setAutoFillBackground(true);
  centralWidget()->setWindowOpacity(0.8);
  centralWidget()->setMinimumSize(300, 200);
  setMinimumSize(700, 500);

  readSettings();
}