Ejemplo n.º 1
0
int tool_main_core(int argc, char** argv) {
    SkCommandLineFlags::Parse(argc, argv);

    SkAutoGraphics ag;

    SkString outputDir;
    if (FLAGS_outputDir.count() > 0) {
        outputDir = FLAGS_outputDir[0];
        if (!sk_mkdir(outputDir.c_str())) {
            SkDebugf("Unable to mkdir '%s'\n", outputDir.c_str());
            return 1;
        }
    }

    SkTArray<SkString> files;
    process_input_files(FLAGS_inputPaths, &files);

    size_t maximumPathLength = 0;
    for (int i = 0; i < files.count(); i ++) {
        SkString basename = SkOSPath::Basename(files[i].c_str());
        maximumPathLength = SkTMax(maximumPathLength, basename.size());
    }

    int failures = 0;
    for (int i = 0; i < files.count(); i ++) {
        SkString basename = SkOSPath::Basename(files[i].c_str());

        SkFILEStream inputStream;
        inputStream.setPath(files[i].c_str());
        if (!inputStream.isValid()) {
            SkDebugf("Could not open file %s\n", files[i].c_str());
            ++failures;
            continue;
        }

        SkAutoTUnref<SkPicture> picture(
                SkPicture::CreateFromStream(&inputStream));
        if (NULL == picture.get()) {
            SkDebugf("Could not read an SkPicture from %s\n",
                     files[i].c_str());
            ++failures;
            continue;
        }
        SkDebugf("[%6g %6g %6g %6g] %-*s",
            picture->cullRect().fLeft, picture->cullRect().fTop,
            picture->cullRect().fRight, picture->cullRect().fBottom,
            maximumPathLength, basename.c_str());

        SkAutoTDelete<SkWStream> stream(open_stream(outputDir, files[i]));
        if (!stream.get()) {
            ++failures;
            continue;
        }
        if (!pdf_to_stream(picture, stream.get())) {
            SkDebugf("Error in PDF Serialization.");
            ++failures;
        }

        int max_rss_mb = sk_tools::getMaxResidentSetSizeMB();
        if (max_rss_mb >= 0) {
            SkDebugf(" %4dM peak rss", max_rss_mb);
        }

        SkDebugf("\n");
    }
    if (failures != 0) {
        SkDebugf("Failed to render %i of %i PDFs.\n", failures, files.count());
        return 1;
    }

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    int ret = 1;
    int num_utils_enabled = 0;
    int i = 0, file_type = 0;
    settings_t settings;
    cdrecorder_t recorders;
    char *home_directory = getenv("HOME");
    char *audioburn_rc_file = NULL;
    char buf[MAX_BUF_LEN] = {0};

    if (home_directory)
    {
        snprintf(buf, MAX_BUF_LEN,
                 "%s/.audioburnrc", home_directory);
        audioburn_rc_file = buf;
    }

    /* initialize session settings */
    if (settings_initialize(&settings, audioburn_rc_file))
    {
        fprintf(stderr,"Failed to initialize settings object\n");
        exit(1);
    }

    /* setup use of all utilities by default */
    if (settings_enable_utilities(&settings,
                                  (ENABLE_OGGDEC | ENABLE_MPGDEC |
                                   ENABLE_SOX | ENABLE_CDRECORD |
                                   ENABLE_NORMALIZE)))
    {
        fprintf(stderr,"Failed to enable utility settings\n");
        goto cleanup;
    }

    /*
      set other defaults (which can be overriden
      by command line options if specified)
    */
    settings_set_preferred_device_number(&settings,0);
    settings_set_temporary_directory(&settings,"/tmp/");

    /* check command line arguments */
    parse_command_line_args(argc,argv,&settings);

    /* initialize the libaudioburn library */
    if (libaudioburn_initialize(&settings) == 0)
    {
        if (settings.verbose)
        {
            printf("\n");
        }

        if (settings.oggdec_enabled)
        {
            if (settings.verbose)
            {
                printf("oggdec    found at: %s\n",
                       settings.oggdec_path);
            }
            ++num_utils_enabled;
        }
        if (settings.mpgdec_enabled)
        {
            if (settings.verbose)
            {
                printf("mpg321    found at: %s\n",
                       settings.mpgdec_path);
            }
            ++num_utils_enabled;
        }
        if (settings.normalize_enabled)
        {
            if (settings.verbose)
            {
                printf("normalize found at: %s\n",
                       settings.normalize_path);
            }
            ++num_utils_enabled;
        }
        if (settings.sox_enabled)
        {
            if (settings.verbose)
            {
                printf("sox       found at: %s\n",
                       settings.sox_path);
            }
            ++num_utils_enabled;
        }
        if (settings.cdrecord_enabled)
        {
            if (settings.verbose)
            {
                printf("cdrecord  found at: %s\n",
                       settings.cdrecord_path);
            }
            ++num_utils_enabled;
        }

        if (num_utils_enabled)
        {
            if (settings.verbose)
            {
                printf("\n");
            }
        }
        else
        {
            printf("Disabling all utilities makes audio_burn worthless!\n");
        }
    }
    else
    {
        fprintf(stderr,"Failed to initialize the libaudioburn "
                "library.\nProgram terminating.\n");
        goto cleanup;
    }

    if (strlen(settings.config_file) && settings.verbose)
    {
        fprintf(stderr,"Read Config options from %s\n", settings.config_file);
    }

    /* probe for cdrecorder information (if enabled) */
    if (settings.cdrecord_enabled)
    {
        if (cdrecord_get_recorder_info(&settings,&recorders))
        {
            fprintf(stderr,"Failed to get cdrecorder information.\n");
            fprintf(stderr,"Please make sure that you have configured a");
            fprintf(stderr," cdrecorder for normal use (i.e. it\nshows up");
            fprintf(stderr," in the output of \"cdrecord -scanbus\").\n\n");
            fprintf(stderr,"For some more information please visit:\n\n");
            fprintf(stderr,"http://mlug.missouri.edu/~rjudd/projects/"
                    "CD-Writing.html\n");
            goto cleanup;
        }
        else if (strlen(settings.atapi_device))
        {
            printf("Using specified ATAPI device %s by user request\n",
                   settings.atapi_device);
        }
        else
        {
            cdrecord_print_recorder_info(&recorders);
            printf("\n");

            /* make sure the preferred device (if any is valid) */
            if ((settings.preferred_device_number < 0) ||
                (settings.preferred_device_number >=
                 recorders.num_devices))
            {
                fprintf(stderr,"Specified cd burning device %d was not "
                        "detected.\nPlease specify another device!\n",
                        settings.preferred_device_number);
                goto cleanup;
            }
            else if (settings.verbose)
            {
                printf("Using CD burning device number %d\n",
                       settings.preferred_device_number);
            }
        }
    }

    /* see if we have any work to do */
    if ((settings.num_input_files == 0) || (num_utils_enabled == 0))
    {
        fprintf(stderr,"\nNothing to do.  Program Terminating.\n");
        goto cleanup;
    }

    /*
      run through the specified input files and
      explode any detected playlists
    */
  playlist_explode:
    for(i = 0; i < settings.num_input_files; i++)
    {
        file_type = get_file_type(settings.input_files[i]);
        switch(file_type)
        {
            case FILE_TYPE_M3U:
            {
                int val = settings_add_m3u_playlist_file(
                    &settings, settings.input_files[i]);
                if (val)
                {
                    fprintf(stderr, "Failed to add m3u playlist "
                            "contents: ");
                    switch(val)
                    {
                        case 1:
                            fprintf(stderr,"Cannot expand list\n");
                            return ret;
                        case -1:
                            fprintf(stderr,
                                    "Too many files specified\n");
                            return ret;
                        case -2:
                            fprintf(stderr,
                                    "Invalid file in playlist\n");
                            return ret;
                        default:
                            fprintf(stderr,"Unknown error\n");
                            return ret;
                    }
                }
                goto playlist_explode;
            }
        }
    }

    /*
      compute total length of tracks specified and compare
      against the total cd length.  error exit if the tracks
      are longer than the specified audio disc length
    */
    if (check_filelist_with_cd_length(
            settings.target_disc_len_in_minutes, settings.input_files,
            settings.num_input_files, settings.verbose))
    {
        printf("\n*** There are too many songs to burn to a %d minute "
               "audio CD!\n", settings.target_disc_len_in_minutes);
        printf(" Please specify fewer songs to burn at a time, or use\n"
               " the --cdlength option to specify that your disc can\n"
               " hold more audio.\n");
        exit(1);
    }

    /* process/decode all input files to have them ready for burning */
    if (process_input_files(&settings))
    {
        fprintf(stderr,"Failed to process input files.\n");
        fprintf(stderr,"Please contact the author.  Terminating.\n");
        goto cleanup;
    }

    /* if specified, normalize all outputted files to each other */
    if (settings.normalize_enabled)
    {
        if (normalize_output_files(&settings))
        {
            fprintf(stderr,"Failed to normalize outputted wav files.\n");
            fprintf(stderr,"Please contact the author.  Terminating.\n");
            goto cleanup;
        }
    }

    /*
      now that we've edited the files, make the permissions more
      user friendly (for the case that we are being run setuid)
    */
    fix_output_file_permissions(&settings);

    /* finally, burn the data */
    if (settings.cdrecord_enabled)
    {
        if (burn_cd(&settings,&recorders))
        {
            fprintf(stderr,"Failed to write cd track data.\n");
            fprintf(stderr,"Please contact the author.  Terminating.\n");
            goto cleanup;
        }
        else
        {
            if (settings.verbose)
            {
                printf("Removing temporary files ... ");
            }
            if (settings.clean_tmp_files)
            {
                clean_temporary_files(&settings);
            }
            if (settings.verbose)
            {
                printf("done.\n");
            }
            printf("CD Burning Complete!\n");
        }
    }

    /* if we get here, all is well */
    ret = 0;

  cleanup:

    /* uninitialize session settings */
    settings_uninitialize(&settings);

    return ret;
}