Merge branch 'lisp-func-type-decls' into 'master'
[emacs.git] / lib-src / be_resources.cc
blobe91ee315803fdabb6d34ee3d265f002f254a3cba
1 /* Haiku window system support
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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.
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.
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/>. */
19 #include <config.h>
21 #include <cstdio>
22 #include <cstring>
23 #include <cstdlib>
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>
36 using namespace std;
38 static void
39 be_perror (status_t code, char *arg)
41 if (code != B_OK)
43 switch (code)
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);
73 else
74 abort ();
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");
81 int
82 main (int argc, char **argv)
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);
94 if (scale32.InitCheck () != B_OK
95 || scale16.InitCheck () != B_OK)
97 fprintf (stderr, "Bitmap initialization ran out of memory\n");
98 return EXIT_FAILURE;
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);
106 if (argc != 3)
108 printf ("be-resources ICON FILE: make FILE appropriate for Emacs.\n");
109 return EXIT_FAILURE;
112 code = file.SetTo (argv[2], B_READ_WRITE);
113 if (code != B_OK)
115 be_perror (code, argv[2]);
116 return 0;
118 code = info.SetTo (&file);
119 if (code != B_OK)
121 be_perror (code, argv[2]);
122 return 0;
124 code = info.SetAppFlags (B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY);
125 if (code != B_OK)
127 be_perror (code, argv[2]);
128 return 0;
131 icon = BTranslationUtils::GetBitmapFile (argv[1], NULL);
133 if (!icon)
135 be_perror (B_ERROR, argv[1]);
136 return EXIT_FAILURE;
139 scale32.AddChild (&scale32view);
140 scale16.AddChild (&scale16view);
142 if (!scale32view.LockLooper ()
143 || !scale16view.LockLooper ())
145 fprintf (stderr, "Failed to lock bitmap looper\n");
146 return EXIT_FAILURE;
149 scale32view.DrawBitmapAsync (icon, scale32.Bounds ());
150 scale16view.DrawBitmapAsync (icon, scale16.Bounds ());
152 scale32view.Sync ();
153 scale16view.Sync ();
155 info.SetIcon (&scale16, B_MINI_ICON);
156 info.SetIcon (&scale32, B_LARGE_ICON);
157 info.SetSignature ("application/x-vnd.GNU-emacs");
159 v = strtok (v, ".");
160 vinfo.major = atoi (v);
162 v = strtok (NULL, ".");
163 vinfo.middle = atoi (v);
165 v = strtok (NULL, ".");
166 vinfo.minor = v ? atoi (v) : 0;
168 vinfo.variety = 0;
169 vinfo.internal = 0;
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);
176 info.SetVersionInfo (&vinfo, B_APP_VERSION_KIND);
178 exit (EXIT_SUCCESS);