root/lib-src/be_resources.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. be_perror
  2. main

     1 /* Haiku window system support
     2    Copyright (C) 2021-2023 Free Software Foundation, Inc.
     3 
     4 This file is part of GNU Emacs.
     5 
     6 GNU Emacs is free software: you can redistribute it and/or modify
     7 it under the terms of the GNU General Public License as published by
     8 the Free Software Foundation, either version 3 of the License, or (at
     9 your option) any later version.
    10 
    11 GNU Emacs is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    18 
    19 #include <config.h>
    20 
    21 #include <cstdio>
    22 #include <cstring>
    23 #include <cstdlib>
    24 
    25 #include <SupportDefs.h>
    26 #include <Path.h>
    27 #include <AppFileInfo.h>
    28 #include <TranslationUtils.h>
    29 #include <Application.h>
    30 #include <Catalog.h>
    31 #include <Roster.h>
    32 #include <Bitmap.h>
    33 #include <Rect.h>
    34 #include <View.h>
    35 
    36 using namespace std;
    37 
    38 static void
    39 be_perror (status_t code, char *arg)
    40 {
    41   if (code != B_OK)
    42     {
    43       switch (code)
    44         {
    45         case B_BAD_VALUE:
    46           fprintf (stderr, "%s: Bad value\n", arg);
    47           break;
    48         case B_ENTRY_NOT_FOUND:
    49           fprintf (stderr, "%s: Not found\n", arg);
    50           break;
    51         case B_PERMISSION_DENIED:
    52           fprintf (stderr, "%s: Permission denied\n", arg);
    53           break;
    54         case B_NO_MEMORY:
    55           fprintf (stderr, "%s: No memory\n", arg);
    56           break;
    57         case B_LINK_LIMIT:
    58           fprintf (stderr, "%s: Link limit reached\n", arg);
    59           break;
    60         case B_BUSY:
    61           fprintf (stderr, "%s: Busy\n", arg);
    62           break;
    63         case B_NO_MORE_FDS:
    64           fprintf (stderr, "%s: No more file descriptors\n", arg);
    65           break;
    66         case B_FILE_ERROR:
    67           fprintf (stderr, "%s: File error\n", arg);
    68           break;
    69         default:
    70           fprintf (stderr, "%s: Unknown error\n", arg);
    71         }
    72     }
    73   else
    74     abort ();
    75 
    76   fprintf (stderr, "Setting resources failed on the `src/Emacs' binary.\n"
    77            "This may result in the installed `Emacs' binary not launching\n"
    78            " from the tracker, but is inconsequential during packaging.\n");
    79 }
    80 
    81 int
    82 main (int argc, char **argv)
    83 {
    84   BApplication app ("application/x-vnd.GNU-emacs-resource-helper");
    85   BFile file;
    86   BBitmap *icon;
    87   BBitmap scale32 (BRect (0, 0, 31, 31), B_RGBA32, true);
    88   BBitmap scale16 (BRect (0, 0, 15, 15), B_RGBA32, true);
    89   BAppFileInfo info;
    90   status_t code;
    91   struct version_info vinfo;
    92   char *v = strdup (PACKAGE_VERSION);
    93 
    94   if (scale32.InitCheck () != B_OK
    95       || scale16.InitCheck () != B_OK)
    96     {
    97       fprintf (stderr, "Bitmap initialization ran out of memory\n");
    98       return EXIT_FAILURE;
    99     }
   100 
   101   BView scale32view (scale32.Bounds (), NULL,
   102                      B_FOLLOW_NONE, B_WILL_DRAW);
   103   BView scale16view (scale16.Bounds (), NULL,
   104                      B_FOLLOW_NONE, B_WILL_DRAW);
   105 
   106   if (argc != 3)
   107     {
   108       printf ("be-resources ICON FILE: make FILE appropriate for Emacs.\n");
   109       return EXIT_FAILURE;
   110     }
   111 
   112   code = file.SetTo (argv[2], B_READ_WRITE);
   113   if (code != B_OK)
   114     {
   115       be_perror (code, argv[2]);
   116       return 0;
   117     }
   118   code = info.SetTo (&file);
   119   if (code != B_OK)
   120     {
   121       be_perror (code, argv[2]);
   122       return 0;
   123     }
   124   code = info.SetAppFlags (B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY);
   125   if (code != B_OK)
   126     {
   127       be_perror (code, argv[2]);
   128       return 0;
   129     }
   130 
   131   icon = BTranslationUtils::GetBitmapFile (argv[1], NULL);
   132 
   133   if (!icon)
   134     {
   135       be_perror (B_ERROR, argv[1]);
   136       return EXIT_FAILURE;
   137     }
   138 
   139   scale32.AddChild (&scale32view);
   140   scale16.AddChild (&scale16view);
   141 
   142   if (!scale32view.LockLooper ()
   143       || !scale16view.LockLooper ())
   144     {
   145       fprintf (stderr, "Failed to lock bitmap looper\n");
   146       return EXIT_FAILURE;
   147     }
   148 
   149   scale32view.DrawBitmapAsync (icon, scale32.Bounds ());
   150   scale16view.DrawBitmapAsync (icon, scale16.Bounds ());
   151 
   152   scale32view.Sync ();
   153   scale16view.Sync ();
   154 
   155   info.SetIcon (&scale16, B_MINI_ICON);
   156   info.SetIcon (&scale32, B_LARGE_ICON);
   157   info.SetSignature ("application/x-vnd.GNU-emacs");
   158 
   159   v = strtok (v, ".");
   160   vinfo.major = atoi (v);
   161 
   162   v = strtok (NULL, ".");
   163   vinfo.middle = atoi (v);
   164 
   165   v = strtok (NULL, ".");
   166   vinfo.minor = v ? atoi (v) : 0;
   167 
   168   vinfo.variety = 0;
   169   vinfo.internal = 0;
   170 
   171   strncpy ((char *) &vinfo.short_info, PACKAGE_VERSION,
   172            sizeof vinfo.short_info - 1);
   173   strncpy ((char *) &vinfo.long_info, PACKAGE_STRING,
   174            sizeof vinfo.long_info - 1);
   175 
   176   info.SetVersionInfo (&vinfo, B_APP_VERSION_KIND);
   177 
   178   exit (EXIT_SUCCESS);
   179 }

/* [<][>][^][v][top][bottom][index][help] */