From 89cd09b305d8f61529136ee367dddf773c31c0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 5 Nov 2003 11:03:24 +0000 Subject: [PATCH] Added installsound, rmattr. Committed translate from Jonas Sundstrom git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5257 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/Jamfile | 9 ++ src/apps/bin/installsound.cpp | 91 ++++++++++++ src/apps/bin/rmattr.cpp | 42 ++++++ src/apps/bin/translate.cpp | 266 ++++++++++++++++++++++++++++++++++ 4 files changed, 408 insertions(+) create mode 100644 src/apps/bin/installsound.cpp create mode 100644 src/apps/bin/rmattr.cpp create mode 100644 src/apps/bin/translate.cpp diff --git a/src/apps/bin/Jamfile b/src/apps/bin/Jamfile index d7399855ea..eeb9789851 100644 --- a/src/apps/bin/Jamfile +++ b/src/apps/bin/Jamfile @@ -21,6 +21,14 @@ StdBinCommands yes.cpp : be ; +StdBinCommands + translate.cpp + : be translation ; + +StdBinCommands + installsound.cpp + : be media ; + StdBinCommands catattr.cpp roster.cpp @@ -44,6 +52,7 @@ StdBinCommands ps.c renice.c rescan.c + rmattr.cpp sysinfo.c unchop.c unmount.c diff --git a/src/apps/bin/installsound.cpp b/src/apps/bin/installsound.cpp new file mode 100644 index 0000000000..e052147da8 --- /dev/null +++ b/src/apps/bin/installsound.cpp @@ -0,0 +1,91 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2001-2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: installsound.cpp +// Author: Jérôme Duval +// Description: manages sound events +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include +#include + +void +usage(void) +{ + printf("installsound eventname filename\n"); + printf(" installs a new named sound event in the Sounds preferences panel.\n"); + printf("installsound --list\n"); + printf(" lists all sound events.\n"); + printf("installsound --test eventname\n"); + printf(" prints the file for the given event name, or nothing and returns error if none.\n"); + printf("installsound --clear eventname\n"); + printf(" clears a named event in the Sounds preferences panel.\n"); + printf("installsound --remove eventname\n"); + printf(" removes a named event from the Sounds preferences panel.\n"); + exit(1); +} + +int main(int argc, const char **argv) +{ + // Make sure we have the minimum number of arguments. + if (argc < 2) usage(); + + BApplication app("application/x-vnd.be.installsound"); + + BMediaFiles mfiles; + + if(strcmp(argv[1], "--list")==0) { + mfiles.RewindRefs(BMediaFiles::B_SOUNDS); + + BString name; + entry_ref ref; + while(mfiles.GetNextRef(&name,&ref) == B_OK) { + printf("%s:\t%s\n", name.String(),BPath(&ref).Path()); + } + } else { + if (argc != 3) usage(); + + if(strcmp(argv[1], "--test")==0) { + entry_ref ref; + if(mfiles.GetRefFor(BMediaFiles::B_SOUNDS, argv[2], &ref) == B_OK) + printf("%s\n", BPath(&ref).Path()); + else { + printf("%s: No such sound event\n", argv[2]); + exit(1); + } + } else if(strcmp(argv[1], "--clear")==0) { + entry_ref ref; + if(mfiles.GetRefFor(BMediaFiles::B_SOUNDS, argv[2], &ref) == B_OK) + mfiles.RemoveRefFor(BMediaFiles::B_SOUNDS, argv[2], ref); + else { + printf("clear %s: No such sound event\n", argv[2]); + exit(1); + } + } else if(strcmp(argv[1], "--remove")==0) { + if(mfiles.RemoveItem(BMediaFiles::B_SOUNDS, argv[2]) != B_OK) { + printf("remove %s: No such sound event\n", argv[2]); + exit(1); + } + } else { + entry_ref ref; + if(get_ref_for_path(argv[2], &ref)!=B_OK || !BEntry(&ref, true).Exists()) { + printf("error: %s not found\n", argv[2]); + exit(1); + } + + mfiles.SetRefFor(BMediaFiles::B_SOUNDS, argv[1], ref); + } + } + + exit(0); +} diff --git a/src/apps/bin/rmattr.cpp b/src/apps/bin/rmattr.cpp new file mode 100644 index 0000000000..a80f7deb1d --- /dev/null +++ b/src/apps/bin/rmattr.cpp @@ -0,0 +1,42 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2001-2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: rmattr.cpp +// Author: Jérôme Duval +// Description: remove an attribute from a file +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include + +int main(int32 argc, const char **argv) +{ + // Make sure we have the minimum number of arguments. + if (argc < 3) { + printf("usage: %s attr filename1 [filename2...]\n", argv[0]); + printf(" attr is the name of an attribute of the file\n"); + exit(0); + } + + for(int32 i=2; i +#include + +#include +#include +#include +#include +#include + +class TranslateApp : public BApplication +{ + public: + TranslateApp (void); + + virtual void ReadyToRun (void); + virtual void ArgvReceived (int32 argc, char **argv); + + private: + + void PrintUsage (void); + void ListTranslators (void); + uint32 GetTypecodeForOutputMime (const char * a_mime); + void RemoveOutputFile (char * path); + + bool m_got_arguments; + BTranslatorRoster * translator_roster; + int32 translators_total; + translator_id * translator_array; +}; + +int main() +{ + new TranslateApp (); + be_app->Run(); + + return B_OK; +} + +TranslateApp::TranslateApp (void) : + BApplication ("application/x-vnd.obos-translate"), + m_got_arguments (false), + translator_roster (BTranslatorRoster::Default()), + translators_total (0), + translator_array (NULL) +{ + translator_roster->GetAllTranslators (& translator_array, & translators_total); +} + +void TranslateApp::ArgvReceived (int32 argc, char ** argv) +{ + status_t status = B_OK; + + BString first_arg = argv[1]; + first_arg.ToLower(); + + // --help + if (first_arg.IFindFirst("--help") == 0) + { + m_got_arguments = true; + PrintUsage(); + return; + } + + // --list + if (first_arg.IFindFirst("--list") == 0) + { + m_got_arguments = true; + ListTranslators(); + return; + } + + if (argc != 4) + return; + + m_got_arguments = true; + + // input file + BFile in_file (argv[1], B_READ_ONLY); + status = in_file.InitCheck(); + + if (status != B_OK) + { + printf("translate: %s : %s\n", argv[1], strerror(status)); + exit (-1); + } + + // find input translator + translator_info best_suited_translator; + status = translator_roster->Identify(& in_file, NULL, & best_suited_translator); + + // get typecode of output format + uint32 out_format = 0; + BMimeType mime (argv[3]); + + if (mime.IsValid() && (! mime.IsSupertypeOnly())) // MIME-string + { + out_format = GetTypecodeForOutputMime(argv[3]); + } + else // 4-byte code + { + if (strlen(argv[3]) == 4) + out_format = (uint32) argv[3]; + else + out_format = 0; + } + + if (out_format == 0) + { + printf("bad format: %s\nformat is 4-byte type code or full MIME type\n", argv[3]); + exit (-1); + } + + // output file + BFile out_file (argv[2], B_READ_WRITE | B_CREATE_FILE | B_FAIL_IF_EXISTS); + status = out_file.InitCheck(); + + if (status != B_OK) + { + printf("translate: %s : %s\n", argv[2], strerror(status)); + exit (-1); + } + + // translate + BMallocIO * malloc_io = new BMallocIO; + + status = translator_roster->Translate(& in_file, NULL, NULL, malloc_io, best_suited_translator.group); + + if (status != B_OK) + { + printf("translate: translation of %s to base format: %s\n", argv[1], strerror(status)); + delete malloc_io; + RemoveOutputFile(argv[2]); + exit (-1); + } + + in_file.Unset(); + + status = translator_roster->Translate(malloc_io, NULL, NULL, & out_file, out_format); + + if (status != B_OK) + { + printf("translate: translation from base format to %s: %s\n", argv[3], strerror(status)); + delete malloc_io; + RemoveOutputFile(argv[2]); + exit (-1); + } + + delete malloc_io; + out_file.Unset(); + + // add filetype attribute + update_mime_info(argv[2], 0, 1, 0); +} + +void TranslateApp::ReadyToRun (void) +{ + if (m_got_arguments == false) + PrintUsage(); + + PostMessage(B_QUIT_REQUESTED); +} + +void TranslateApp::PrintUsage (void) +{ + printf ("usage: translate { --list | input output format }\n"); +} + +void TranslateApp::ListTranslators (void) +{ + const char * translator_name = NULL; + const char * translator_info = NULL; + int32 translator_version = 0; + + for (int32 i = 0; i < translators_total; i++) + { + translator_roster->GetTranslatorInfo(translator_array[i], & translator_name, & translator_info, & translator_version); + printf("name: %s\ninfo: %s\nversion: %.2f\n", translator_name, translator_info, translator_version/100.); + + const translation_format * format = NULL; + int32 format_num = 0; + + translator_roster->GetInputFormats(translator_array[i], & format, & format_num); + + for (int32 ii = 0; ii < format_num; ii++) + { + printf("input:\t"); + + printf("'%c", (short) (format[ii].type >> 24)); + printf("%c", (short) ((format[ii].type << 8) >> 24)); + printf("%c", (short) ((format[ii].type << 16) >> 24)); + printf("%c' ", (short) ((format[ii].type << 24) >> 24)); + + printf("(%c", (short) (format[ii].group >> 24)); + printf("%c", (short) ((format[ii].group << 8) >> 24)); + printf("%c", (short) ((format[ii].group << 16) >> 24)); + printf("%c) ", (short) ((format[ii].group << 24) >> 24)); + + printf("%.1f ", format[ii].quality); + printf("%.1f ", format[ii].capability); + + printf("%s ; ", format[ii].MIME); + printf("%s\n", format[ii].name); + } + + translator_roster->GetOutputFormats(translator_array[i], & format, & format_num); + + for (int32 ii = 0; ii < format_num; ii++) + { + printf("output:\t"); + + printf("'%c", (short) (format[ii].type >> 24)); + printf("%c", (short) ((format[ii].type << 8) >> 24)); + printf("%c", (short) ((format[ii].type << 16) >> 24)); + printf("%c' ", (short) ((format[ii].type << 24) >> 24)); + + printf("(%c", (short) (format[ii].group >> 24)); + printf("%c", (short) ((format[ii].group << 8) >> 24)); + printf("%c", (short) ((format[ii].group << 16) >> 24)); + printf("%c) ", (short) ((format[ii].group << 24) >> 24)); + + printf("%.1f ", format[ii].quality); + printf("%.1f ", format[ii].capability); + + printf("%s ; ", format[ii].MIME); + printf("%s\n", format[ii].name); + } + + printf("\n"); + } +} + +uint32 TranslateApp::GetTypecodeForOutputMime (const char * a_mime) +{ + for (int32 i = 0; i < translators_total; i++) + { + const translation_format * format = NULL; + int32 format_num = 0; + + translator_roster->GetOutputFormats(translator_array[i], & format, & format_num); + + for (int32 ii = 0; ii < format_num; ii++) + { + if (! strcmp(a_mime, format[ii].MIME)) + return (format[ii].type); + } + } + + return 0; +} + +void TranslateApp::RemoveOutputFile (char * path) +{ + BEntry entry (path); + entry.Remove(); +}