コード例 #1
0
std::string basename_part (const std::string& spec)
{
  std::string fname = filename_part(spec);
  // scan back through filename until a '.' is found and remove suffix
  // the whole filename is the basename if there is no '.'
  std::string::size_type i = fname.find_last_of('.');
  // observe Unix convention that a dot at the start of a filename is part of the basename, not the extension
  if (i != 0 && i != std::string::npos)
    fname.erase(i, fname.size()-i);
  return fname;
}
コード例 #2
0
std::string extension_part (const std::string& spec)
{
  std::string fname = filename_part(spec);
  // scan back through filename until a '.' is found and remove prefix;
  std::string::size_type i = fname.find_last_of('.');
  // observe Unix convention that a dot at the start of a filename is part of the name, not the extension;
  if (i != 0 && i != std::string::npos)
    fname.erase(0, i+1);
  else
    fname.erase();
  return fname;
}
コード例 #3
0
ファイル: toc.c プロジェクト: AhmadTux/DragonFlyBSD
/* Routine to add an entry to the table of contents */
int
toc_add_entry (char *tocname, int level, char *node_name, char *anchor)
{
  char *expanded_node, *d;
  char *s = NULL;
  char *filename = NULL;

  if (!node_name)
    node_name = "";

  /* I assume that xrealloc behaves like xmalloc if toc_entry_alist is
     NULL */
  toc_entry_alist = xrealloc (toc_entry_alist,
                              (toc_counter + 1) * sizeof (TOC_ENTRY_ELT *));

  toc_entry_alist[toc_counter] = xmalloc (sizeof (TOC_ENTRY_ELT));

  if (html)
    {
      /* We need to insert the expanded node name into the toc, so
         that when we eventually output the toc, its <a ref= link will
         point to the <a name= tag created by cm_node in the navigation
         bar.  We cannot expand the containing_node member, for the
         reasons explained in the WARNING below.  We also cannot wait
         with the node name expansion until the toc is actually output,
         since by that time the macro definitions may have been changed.
         So instead we store in the tocname member the expanded node
         name and the toc name concatenated together (with the necessary
         html markup), since that's how they are output.  */
      if (!anchor)
        s = expanded_node = expand_node_name (node_name);
      else
        expanded_node = anchor;
      if (splitting)
	{
	  if (!anchor)
	    filename = nodename_to_filename (expanded_node);
	  else
	    filename = filename_part (current_output_filename);
	}
      if (!anchor)
        /* Need to HTML-escape the expanded node name like
            add_anchor_name does...  */
        d = escaped_anchor_name (expanded_node);
      else
        /* Section outside any node, they provided explicit anchor.  */
        d = xstrdup(anchor);
        
      /* Add space for the "> which may be needed, and the tocname */  
      d = xrealloc (d, strlen (d) + strlen (tocname) + 3);
      if (!anchor)
        strcat (d, "\">");
      strcat (d, tocname);
      free (tocname);       /* it was malloc'ed by substring() */
      free (expanded_node);
      toc_entry_alist[toc_counter]->name = d;
    }
  else
    toc_entry_alist[toc_counter]->name = tocname;
  /* WARNING!  The node name saved in containing_node member must
     be the node name with _only_ macros expanded (the macros in
     the node name are expanded by cm_node when it grabs the name
     from the @node directive).  Non-macros, like @value, @@ and
     other @-commands must NOT be expanded in containing_node,
     because toc_find_section_of_node looks up the node name where
     they are also unexpanded.  You *have* been warned!  */
  toc_entry_alist[toc_counter]->containing_node = xstrdup (node_name);
  toc_entry_alist[toc_counter]->level = level;
  toc_entry_alist[toc_counter]->number = toc_counter;
  toc_entry_alist[toc_counter]->html_file = filename;

  /* have to be done at least */
  return toc_counter++;
}
コード例 #4
0
ファイル: pngquant.c プロジェクト: JiangySky/pngquant
static pngquant_error read_image(liq_attr *options, const char *filename, int using_stdin, png24_image *input_image_p, liq_image **liq_image_p, bool keep_input_pixels, bool verbose)
{
    FILE *infile;

    if (using_stdin) {
        set_binary_mode(stdin);
        infile = stdin;
    } else if ((infile = fopen(filename, "rb")) == NULL) {
        fprintf(stderr, "  error: cannot open %s for reading\n", filename);
        return READ_ERROR;
    }

    pngquant_error retval;
    #pragma omp critical (libpng)
    {
        retval = rwpng_read_image24(infile, input_image_p, verbose);
    }

    if (!using_stdin) {
        fclose(infile);
    }

    if (retval) {
        fprintf(stderr, "  error: cannot decode image %s\n", using_stdin ? "from stdin" : filename_part(filename));
        return retval;
    }

    *liq_image_p = liq_image_create_rgba_rows(options, (void**)input_image_p->row_pointers, input_image_p->width, input_image_p->height, input_image_p->gamma);

    if (!*liq_image_p) {
        return OUT_OF_MEMORY_ERROR;
    }

    if (!keep_input_pixels) {
        if (LIQ_OK != liq_image_set_memory_ownership(*liq_image_p, LIQ_OWN_ROWS | LIQ_OWN_PIXELS)) {
            return OUT_OF_MEMORY_ERROR;
        }
        input_image_p->row_pointers = NULL;
        input_image_p->rgba_data = NULL;
    }

    return SUCCESS;
}
コード例 #5
0
ファイル: pngquant.c プロジェクト: JiangySky/pngquant
static pngquant_error write_image(png8_image *output_image, png24_image *output_image24, const char *outname, struct pngquant_options *options)
{
    FILE *outfile;
    char *tempname = NULL;

    if (options->using_stdout) {
        set_binary_mode(stdout);
        outfile = stdout;

        if (output_image) {
            verbose_printf(options, "  writing %d-color image to stdout", output_image->num_palette);
        } else {
            verbose_printf(options, "  writing truecolor image to stdout");
        }
    } else {
        tempname = temp_filename(outname);
        if (!tempname) return OUT_OF_MEMORY_ERROR;

        if ((outfile = fopen(tempname, "wb")) == NULL) {
            fprintf(stderr, "  error: cannot open '%s' for writing\n", tempname);
            free(tempname);
            return CANT_WRITE_ERROR;
        }

        if (output_image) {
            verbose_printf(options, "  writing %d-color image as %s", output_image->num_palette, filename_part(outname));
        } else {
            verbose_printf(options, "  writing truecolor image as %s", filename_part(outname));
        }
    }

    pngquant_error retval;
    #pragma omp critical (libpng)
    {
        if (output_image) {
            retval = rwpng_write_image8(outfile, output_image);
        } else {
            retval = rwpng_write_image24(outfile, output_image24);
        }
    }

    if (!options->using_stdout) {
        fclose(outfile);

        if (SUCCESS == retval) {
            // Image has been written to a temporary file and then moved over destination.
            // This makes replacement atomic and avoids damaging destination file on write error.
            if (!replace_file(tempname, outname, options->force)) {
                retval = CANT_WRITE_ERROR;
            }
        }

        if (retval) {
            unlink(tempname);
        }
    }
    free(tempname);

    if (retval && retval != TOO_LARGE_FILE) {
        fprintf(stderr, "  error: failed writing image to %s\n", outname);
    }

    return retval;
}
コード例 #6
0
std::string filespec_to_relative_path(const std::string& root, const std::string& spec)
{
  return create_filespec(folder_to_relative_path(root, folder_part(spec)),filename_part(spec));
}
コード例 #7
0
std::string filespec_to_path (const std::string& path, const std::string& spec)
{
  return create_filespec(folder_to_path(path, folder_part(spec)),filename_part(spec));
}