Пример #1
0
void
dump_translation_formats(BString &bstr, const translation_format *pfmts,
	int32 nfmts)
{
	BString *str1 = NULL;
	for (int i = 0; i < nfmts; i++) {
		BString string = B_TRANSLATE("\nType: '%1' (%2)\n"
			"Group: '%3' (%4)\n"
			"Quality: %5\n"
			"Capability: %6\n"
			"MIME Type: %7\n"
			"Name: %8\n");
		string.ReplaceFirst("%1", char_format(pfmts[i].type));
		string.ReplaceFirst("%2", hex_format(pfmts[i].type));
		string.ReplaceFirst("%3", char_format(pfmts[i].group));
		string.ReplaceFirst("%4", hex_format(pfmts[i].group));
		char str2[127] = { 0 };
		sprintf(str2, "%f", pfmts[i].quality);
		string.ReplaceFirst("%5", str2 );
		str2[0] = '\0';
		sprintf(str2, "%f", pfmts[i].capability);
		string.ReplaceFirst("%6",  str2 );
		string.ReplaceFirst("%7", pfmts[i].MIME);
		string.ReplaceFirst("%8", pfmts[i].name);
		if (i == 0)
			str1 = new BString(string);
		else
			str1->Append(string);
	}
	bstr = str1->String();
}
Пример #2
0
void
dump_translation_formats(BString &bstr, const translation_format *pfmts,
	int32 nfmts)
{
	for (int i = 0; i < nfmts; i++) {
		bstr << "\nType: '" << char_format(pfmts[i].type) << "' (" <<
			hex_format(pfmts[i].type) << ")\n";
		bstr << "Group: '" << char_format(pfmts[i].group) << "' (" <<
			hex_format(pfmts[i].group) << ")\n";
		bstr << "Quality: " << pfmts[i].quality << "\n";
		bstr << "Capability: " << pfmts[i].capability << "\n";
		bstr << "MIME Type: " << pfmts[i].MIME << "\n";
		bstr << "Name: " << pfmts[i].name << "\n";
	}
}
Пример #3
0
// Send information about the currently open image to the
// BApplication object so it can send it to the InfoWindow
void
ImageView::UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
	const translator_info &tinfo, BTranslatorRoster *proster)
{
	BMessage msg(M_INFO_WINDOW_TEXT);
	BString bstr;

	bstr = B_TRANSLATE("Image: %1\n"
		"Color Space: %2 (%3)\n"
		"Dimensions: %4 x %5\n"
		"Bytes per Row: %6\n"
		"Total Bytes: %7\n"
		"\nIdentify Info:\n"
		"ID String: %8\n"
		"MIME Type: %9\n"
		"Type: '%10' (%11)\n"
		"Translator ID: %12\n"
		"Group: '%13' (%14)\n"
		"Quality: %15\n"
		"Capability: %16\n"
		"\nExtension Info:\n");
	bstr.ReplaceFirst("%1", path.Path());
	color_space cs = fpbitmap->ColorSpace();
	bstr.ReplaceFirst("%2", get_color_space_name(cs));
	bstr.ReplaceFirst("%3", hex_format(static_cast<uint32>(cs)));
	char str2[127] = { 0 };
	sprintf(str2, "%ld", fpbitmap->Bounds().IntegerWidth() + 1);
	bstr.ReplaceFirst("%4", str2);
	str2[0] = '\0';
	sprintf(str2, "%ld", fpbitmap->Bounds().IntegerHeight() + 1);
	bstr.ReplaceFirst("%5", str2);
	str2[0] = '\0';
	sprintf(str2, "%ld", fpbitmap->BytesPerRow());
	bstr.ReplaceFirst("%6", str2);
	str2[0] = '\0';
	sprintf(str2, "%ld", fpbitmap->BitsLength());
	bstr.ReplaceFirst("%7", str2);
	bstr.ReplaceFirst("%8", tinfo.name);
	bstr.ReplaceFirst("%9", tinfo.MIME);
	bstr.ReplaceFirst("%10", char_format(tinfo.type));
	bstr.ReplaceFirst("%11", hex_format(tinfo.type));
	str2[0] = '\0';
	sprintf(str2, "%ld", tinfo.translator);
	bstr.ReplaceFirst("%12", str2);
	bstr.ReplaceFirst("%13", char_format(tinfo.group));
	bstr.ReplaceFirst("%14", hex_format(tinfo.group));
	str2[0] = '\0';
	sprintf(str2, "%f", tinfo.quality);
	bstr.ReplaceFirst("%15", str2);
	str2[0] = '\0';
	sprintf(str2, "%f", tinfo.capability);
	bstr.ReplaceFirst("%16", str2);

	int32 document_count = 0, document_index = 0;
	// Translator Info
	const char *tranname = NULL, *traninfo = NULL;
	int32 tranversion = 0;

	if (ioExtension.FindInt32("/documentCount", &document_count) == B_OK) {
		BString str = B_TRANSLATE("Number of Documents: %1\n"
			"\nTranslator Used:\n"
			"Name: %2\n"
			"Info: %3\n"
			"Version: %4\n");
		char str2[127] = { 0 };
		sprintf(str2, "%ld", document_count);
		str.ReplaceFirst("%1", str2);
		str.ReplaceFirst("%2", tranname);
		str.ReplaceFirst("%3", traninfo);
		str2[0] = '\0';
		sprintf(str2, "%d", (int)tranversion);
		str.ReplaceFirst("%4", str2);
		bstr.Append(str.String());
	}
	else
		if (ioExtension.FindInt32("/documentIndex", &document_index) == B_OK) {
			BString str = B_TRANSLATE("Selected Document: %1\n"
				"\nTranslator Used:\n"
				"Name: %2\n"
				"Info: %3\n"
				"Version: %4\n");
			char str2[127] = { 0 };
			sprintf(str2, "%ld", document_index);
			str.ReplaceFirst("%1", str2);
			str.ReplaceFirst("%2", tranname);
			str.ReplaceFirst("%3", traninfo);
			str2[0] = '\0';
			sprintf(str2, "%d", (int)tranversion);
			str.ReplaceFirst("%4", str2);
			bstr.Append(str.String());
		}
		else
			if (proster->GetTranslatorInfo(tinfo.translator, &tranname,
				&traninfo, &tranversion) == B_OK) {
					BString str = B_TRANSLATE("\nTranslator Used:\n"
						"Name: %1\n"
						"Info: %2\n"
						"Version: %3\n");
					str.ReplaceFirst("%1", tranname);
					str.ReplaceFirst("%2", traninfo);
					char str2[127] = { 0 };
					sprintf(str2, "%d", (int)tranversion);
					str.ReplaceFirst("%3", str2);
					bstr.Append(str.String());
			}

	// Translator Input / Output Formats
	int32 nins = 0, nouts = 0;
	const translation_format *pins = NULL, *pouts = NULL;
	if (proster->GetInputFormats(tinfo.translator, &pins, &nins) == B_OK) {
		bstr << B_TRANSLATE("\nInput Formats:");
		dump_translation_formats(bstr, pins, nins);
		pins = NULL;
	}
	if (proster->GetOutputFormats(tinfo.translator, &pouts, &nouts) == B_OK) {
		bstr << B_TRANSLATE("\nOutput Formats:");
		dump_translation_formats(bstr, pouts, nouts);
		pouts = NULL;
	}
	msg.AddString("text", bstr);
	be_app->PostMessage(&msg);
}
Пример #4
0
void sharedq_drain(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3)
    {
        sharedq_help_drain();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "bhvx");

    if (param.help)
    {
        sharedq_help_drain();
        return;
    }
    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    pid_t pid = getpid();

    sq_item_s item = {0};

    struct timespec itm_intrvl;
    struct timespec call_intrvl;
    struct timespec call_start;
    struct timespec call_end;
    do {
        clock_gettime(CLOCK_REALTIME, &call_start);
        if (param.block) {
            item = shr_q_remove_wait(q, &item.buffer, &item.buf_size);
        } else {
            item = shr_q_remove(q, &item.buffer, &item.buf_size);
        }
        clock_gettime(CLOCK_REALTIME, &call_end);
        if (item.status == SH_ERR_ARG) {
            printf("sharedq:  invalid argument for remove function\n");
        } else if (item.status == SH_ERR_EMPTY) {
            if (param.block) {
                item.status = SH_OK;
            }
            printf("sharedq:  queue is empty\n");
        } else if (item.status == SH_ERR_NOMEM) {
            printf("sharedq:  not enough memory to complete remove\n");
        } else if (item.status == SH_OK) {
            timespecsub(&call_end, &call_start, &call_intrvl);
            if (param.hex) {
                hex_format(item.value, item.length);
            } else {
                timespecsub(&call_end, item.timestamp, &itm_intrvl);
                if (param.verbose) {
                    printf("%li.%09li--(%i)--%li.%09li--%li.%09li-->%s\n",
                        call_end.tv_sec, call_end.tv_nsec, pid,
                        itm_intrvl.tv_sec, itm_intrvl.tv_nsec,
                        call_intrvl.tv_sec, call_intrvl.tv_nsec,
                        (char *)item.value);
                } else {
                    printf("-->%s\n", (char *)item.value);
                }
            }
            if (param.block) {
                clock_gettime(CLOCK_REALTIME, &call_start);
                if (param.verbose) {
                    printf("%li.%09li--(%i) sleeping \n", call_start.tv_sec,
                        call_start.tv_nsec, pid);
                }
                struct timespec nano = {.tv_sec = 1, .tv_nsec = 0};
                while(nanosleep(&nano, &nano) < 0) {
                    if (errno != EINTR) {
                        break;
                    }
                }
                clock_gettime(CLOCK_REALTIME, &call_start);
                if (param.verbose) {
                    printf("%li.%09li--(%i) waking \n", call_start.tv_sec,
                        call_start.tv_nsec, pid);
                }
            }
        }
    } while (item.status == SH_OK);


    shr_q_close(&q);
}
Пример #5
0
void sharedq_remove(int argc, char *argv[], int index)
{
    if ((argc - index + 1) < 3 || (argc - index + 1) > 3)
    {
        sharedq_help_remove();
        return;
    }

    modifiers_s param = parse_modifiers(argc, argv, index, "bhx");

    if (param.help) {
        sharedq_help_remove();
        return;
    }

    shr_q_s *q = NULL;
    sh_status_e status = shr_q_open(&q, argv[index + 1], SQ_READ_ONLY);
    if (status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for open function\n");
        return;
    }
    if (status == SH_ERR_ACCESS) {
        printf("sharedq:  permission error for queue name\n");
        return;
    }
    if (status == SH_ERR_EXIST) {
        printf("sharedq:  queue name does not exist\n");
        return;
    }
    if (status == SH_ERR_PATH) {
        printf("sharedq:  error in queue name path\n");
        return;
    }
    if (status == SH_ERR_SYS) {
        printf("sharedq:  system call error\n");
        return;
    }

    sq_item_s item = {0};

    if (param.block) {
        item = shr_q_remove_wait(q, &item.buffer, &item.buf_size);
    } else {
        item = shr_q_remove(q, &item.buffer, &item.buf_size);
    }

    if (item.status == SH_ERR_ARG) {
        printf("sharedq:  invalid argument for remove function\n");
    } else if (item.status == SH_ERR_EMPTY) {
        printf("sharedq:  queue is empty\n");
    } else if (item.status == SH_ERR_NOMEM) {
        printf("sharedq:  not enough memory to complete remove\n");
    } else {
        if (param.hex) {
            hex_format(item.value, item.length);
        } else {
            printf("%s\n", (char *)item.value);
        }
    }

    shr_q_close(&q);
}
Пример #6
0
// Send information about the currently open image to the
// BApplication object so it can send it to the InfoWindow
void
ImageView::UpdateInfoWindow(const BPath &path, BMessage &ioExtension,
	const translator_info &tinfo, BTranslatorRoster *proster)
{
	BMessage msg(M_INFO_WINDOW_TEXT);
	BString bstr;
	
	// Bitmap Info
	bstr << "Image: " << path.Path() << "\n";
	color_space cs = fpbitmap->ColorSpace();
	bstr << "Color Space: " << get_color_space_name(cs) << " (" << 
		hex_format(static_cast<uint32>(cs)) << ")\n";
	bstr << "Dimensions: " << fpbitmap->Bounds().IntegerWidth() + 1 << " x " <<
		fpbitmap->Bounds().IntegerHeight() + 1 << "\n";
	bstr << "Bytes per Row: " << fpbitmap->BytesPerRow() << "\n";
	bstr << "Total Bytes: " << fpbitmap->BitsLength() << "\n";
	
	// Identify Info
	bstr << "\nIdentify Info:\n";
	bstr << "ID String: " << tinfo.name << "\n";
	bstr << "MIME Type: " << tinfo.MIME << "\n";
	bstr << "Type: '" << char_format(tinfo.type) << "' (" <<
		hex_format(tinfo.type) << ")\n";
	bstr << "Translator ID: " << tinfo.translator << "\n";
	bstr << "Group: '" << char_format(tinfo.group) << "' (" <<
		hex_format(tinfo.group) << ")\n";
	bstr << "Quality: " << tinfo.quality << "\n";
	bstr << "Capability: " << tinfo.capability << "\n";
	
	// Extension Info
	bstr << "\nExtension Info:\n";
	int32 document_count = 0, document_index = 0;
	if (ioExtension.FindInt32("/documentCount", &document_count) == B_OK)
		bstr << "Number of Documents: " << document_count << "\n";
	if (ioExtension.FindInt32("/documentIndex", &document_index) == B_OK)
		bstr << "Selected Document: " << document_index << "\n";
	
	// Translator Info
	const char *tranname = NULL, *traninfo = NULL;
	int32 tranversion = 0;
	if (proster->GetTranslatorInfo(tinfo.translator, &tranname, &traninfo,
		&tranversion) == B_OK) {
		bstr << "\nTranslator Used:\n";
		bstr << "Name: " << tranname << "\n";
		bstr << "Info: " << traninfo << "\n";
		bstr << "Version: " << tranversion << "\n";
	}
		
	// Translator Input / Output Formats
	int32 nins = 0, nouts = 0;
	const translation_format *pins = NULL, *pouts = NULL;
	if (proster->GetInputFormats(tinfo.translator, &pins, &nins) == B_OK) {
		bstr << "\nInput Formats:";
		dump_translation_formats(bstr, pins, nins);
		pins = NULL;
	}
	if (proster->GetOutputFormats(tinfo.translator, &pouts, &nouts) == B_OK) {
		bstr << "\nOutput Formats:";
		dump_translation_formats(bstr, pouts, nouts);
		pouts = NULL;
	}
	
	msg.AddString("text", bstr);
	be_app->PostMessage(&msg);
}