Ticket #6318: ListPortLocalization.patch

File ListPortLocalization.patch, 6.7 KB (added by Karvjorm, 14 years ago)

4th ListPortLocalization update including listport.rdef (no idea if resource app_flags are correct)

  • src/bin/Jamfile

     
    4040    idestatus.c
    4141    listarea.c
    4242    listimage.c
    43     listport.c
     43#   listport.c
    4444    listsem.c
    4545    logger.cpp
    4646    lsindex.cpp
     
    240240SubInclude HAIKU_TOP src bin keymap ;
    241241SubInclude HAIKU_TOP src bin less ;
    242242SubInclude HAIKU_TOP src bin listdev ;
     243SubInclude HAIKU_TOP src bin listport ;
    243244SubInclude HAIKU_TOP src bin locale ;
    244245SubInclude HAIKU_TOP src bin make ;
    245246SubInclude HAIKU_TOP src bin makebootable ;
  • src/bin/listport/listport.rdef

     
     1
     2resource app_signature "application/x-vnd.Haiku-listport";
     3
     4resource file_types message;
     5
     6resource app_version {
     7    major  = 1,
     8    middle = 0,
     9    minor  = 0,
     10
     11    /* 0 = development  1 = alpha           2 = beta
     12       3 = gamma        4 = golden master   5 = final */
     13    variety = 2,
     14
     15    internal = 0,
     16
     17    short_info = "listport",
     18    long_info  = "listport ©2001-2003 OpenOS, ©2010 Haiku Inc."
     19};
     20
     21resource app_flags B_MULTIPLE_LAUNCH | B_ARGV_ONLY | B_BACKGROUND_APP ;
  • src/bin/listport/ListPort.cpp

     
     1// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
     2//
     3//  Copyright (c) 2001-2003, OpenBeOS
     4//  Copyright (c) 2010, Haiku Inc.
     5//
     6//  This software is part of the OpenBeOS distribution and is covered
     7//  by the OpenBeOS license.
     8//
     9//
     10//  File:        listport.c (originally, changed to ListPort.cpp by Jorma
     11//               Karvonen <karvonen.jorma @ gmail.com>)
     12//  Author:      Daniel Reinhold (danielre@users.sf.net)
     13//  Description: lists all open ports in the system, organized by team
     14//
     15// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
     16
     17#include <stdio.h>
     18#include <stdlib.h>
     19
     20#include <Application.h>
     21#include <Catalog.h>
     22#include <Locale.h>
     23#include <OS.h>
     24
     25#undef B_TRANSLATE_CONTEXT
     26#define B_TRANSLATE_CONTEXT "ListPort"
     27
     28class ListPort : public BApplication
     29{
     30public:
     31            ListPort();
     32            ListPort(int32 argc, char** argv);
     33            ~ListPort();
     34   
     35    void        ArgvReceived(int32 argc, char** argv);
     36    void        MessageReceived(BMessage* message);
     37    virtual void    ReadyToRun();
     38   
     39private:
     40    void        List_team_ports(team_id id);
     41    void        Show_port_totals(void);
     42    void        AboutRequested();
     43    void        HelpRequested();
     44};
     45
     46
     47ListPort::ListPort()
     48    : BApplication("application/x-vnd.Haiku-listport")
     49{
     50}
     51
     52
     53ListPort::ListPort(int32 argc, char** argv)
     54    : BApplication("application/x-vnd.Haiku-listport")
     55{
     56    if (argc == 1)
     57        ArgvReceived(argc, argv);
     58}
     59
     60
     61ListPort::~ListPort()
     62{
     63}
     64
     65
     66void
     67ListPort::ReadyToRun()
     68{
     69    Quit();
     70}
     71
     72   
     73void
     74ListPort::AboutRequested()
     75{
     76    BString str = B_TRANSLATE("listport\n"
     77        "\twritten by %1\n\n"
     78        "\tThis software is part of the OpenBeOS distribution and is covered\n"
     79        "\tby the OpenBeOS license.\n"
     80        "\tConverted to BApplication by %2\n"
     81        "\tCopyright (c) 2001-2003, OpenBeOS\n"
     82        "\tCopyright %3, Haiku Inc.\n");
     83    str.ReplaceFirst("%1", "Daniel Reinhold (danielre@users.sf.net)");
     84    str.ReplaceFirst("%2", "Jorma Karvonen (karvonen.jorma @ gmail.com)");
     85    str.ReplaceFirst("%3", "2010");
     86    printf("%s\n", str.String());
     87}
     88
     89
     90void
     91ListPort::HelpRequested()
     92{
     93    BString str = B_TRANSLATE("Lists all open ports in the system, organized "
     94        "by team\n"
     95        "Usage: listport [team_id][--help]\n"
     96        "Examples:\n"
     97        "listport\n"
     98        "\tprints all applications and their ports\n\n"
     99        "listport NUMBER\n"
     100        "\tprints information about ports of team NUMBER\n\n"
     101        "listport --help\n"
     102        "\tprints information about application\n"
     103        "\tand this help text\n");
     104    printf("%s\n", str.String());
     105    Quit();
     106}
     107
     108
     109void
     110ListPort::ArgvReceived(int32 argc, char** argv)
     111{
     112    if (argc == 1) {
     113        int32     cookie = 0;
     114        team_info info;
     115       
     116        Show_port_totals();
     117        // list for all teams
     118        while (get_next_team_info(&cookie, &info) >= B_OK)
     119            List_team_ports(info.team);
     120    }
     121    else
     122    {
     123        if (argc == 2) {
     124            if (strcmp(argv[1], "--help") == 0) {
     125                AboutRequested();
     126                HelpRequested();
     127                return;
     128            }
     129        }
     130        Show_port_totals();
     131        // list for each team_id on the command line
     132        while (--argc)
     133            List_team_ports(atoi(*++argv));
     134        Quit();
     135    }
     136    printf("\n");
     137}
     138
     139
     140void
     141ListPort::MessageReceived(BMessage* message)
     142{
     143    switch(message->what)
     144    {
     145        case B_ABOUT_REQUESTED: AboutRequested(); break;
     146        case B_QUIT_REQUESTED: BApplication::QuitRequested(); break;
     147        default: BApplication::MessageReceived(message); break;
     148    }
     149}
     150
     151
     152void
     153ListPort::List_team_ports(team_id id)
     154{
     155    int32      cookie = 0;
     156    port_info  this_port;
     157    team_info  this_team;
     158   
     159    if (get_team_info(id, &this_team) == B_BAD_TEAM_ID) {
     160        printf(B_TRANSLATE("\nteam %ld unknown\n"), id);
     161        return;
     162    }
     163
     164    printf(B_TRANSLATE("\nTEAM %5ld (%s):\n"), id, this_team.args);
     165    printf(B_TRANSLATE_COMMENT("        ID                           name  "
     166        "capacity  queued\n", "A table header, try to keep the end of "
     167        "single words in the same column."));
     168    printf("-----------------------------------------------------------\n");
     169   
     170    while (get_next_port_info(id, &cookie, &this_port) == B_OK) {
     171        printf("%10ld %30s  %8ld  %6ld\n",
     172                this_port.port,
     173                this_port.name,
     174                this_port.capacity,
     175                this_port.queue_count);
     176    }
     177}
     178
     179
     180void
     181ListPort::Show_port_totals(void)
     182{
     183    int32       max = 0, used = 0, left;
     184    system_info sys;
     185   
     186    if (get_system_info(&sys) == B_OK) {
     187        max  = sys.max_ports;
     188        used = sys.used_ports;
     189    }
     190   
     191    left = max - used;
     192   
     193    printf(B_TRANSLATE("port: total: %5ld, used: %5ld, left: %5ld\n"),
     194        max, used, left);
     195}
     196
     197
     198int
     199main(int argc, char **argv)
     200{
     201    new ListPort(argc, argv);
     202    be_app->Run();
     203    be_app->Quit();
     204    return 0;
     205}
  • src/bin/listport/Jamfile

     
     1SubDir HAIKU_TOP src bin listport ;
     2
     3UseLibraryHeaders icon ;
     4
     5Application ListPort :
     6    ListPort.cpp
     7    : be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++)
     8    : listport.rdef
     9;
     10
     11DoCatalogs ListPort :
     12    x-vnd.Haiku-listport
     13    :
     14    ListPort.cpp
     15;