Re: [sqlite] Using application_id
Pardon the "double post" as it were. I was handily informed the mailing list strips attachments. Therefore, for those interested, here's text versions of the header file (rad50.h) and the actual C that does the RADIX-50 conversions (rad50.c): /* == */ #ifndef _RAD50_H #define _RAD50_H #include int rad50enc(const char *, uint16_t *); int rad50dec(uint16_t, char *); int xrad50enc(const char *, uint32_t *); int xrad50dec(uint32_t, char *); #endif /* _RAD50_H */ /* == */ /* * Copyright (c) 2019 C. Gauger-Cosgrove * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include #include #include "rad50.h" #define RAD50TAB " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.*0123456789" int rad50enc(const char *text, uint16_t *value) { size_t i; uint16_t t; const int mult[3] = {1600, 40, 1}; char *c; if (strlen(text) == 0) { *value = 0; return 0; } else if (strlen(text) > 3) { *value = 0x; return 1; } t = 0; for (i = 0; i < strlen(text); ++i) { c = (char *) strchr(RAD50TAB, toupper(text[i])); if (c == NULL) { *value = 0x; return 1; } t += (c - RAD50TAB) * mult[i]; } *value = t; return 0; } int rad50dec(uint16_t value, char *text) { size_t i; const int mult[3] = {1600, 40, 1}; if (value >= 0xFA00) { text[0] = 0; return 1; } for (i = 0; i < 3; ++i) text[i] = RAD50TAB[(value / mult[i]) % 40]; text[3] = 0; return 0; } int xrad50enc(const char *text, uint32_t *value) { size_t i; uint32_t t; const int mult[6] = {10240, 256, 64000, 1600, 40, 1}; char *c; if (strlen(text) == 0) { *value = 0; return 0; } else if (strlen(text) > 6) { *value = 0x; return 1; } t = 0; for (i = 0; i < strlen(text); ++i) { c = (char *) strchr(RAD50TAB, toupper(text[i])); if (c == NULL) { *value = 0x; return 1; } t += (c - RAD50TAB) * mult[i]; } *value = t; return 0; } int xrad50dec(uint32_t value, char *text) { size_t i; const int mult[6] = {10240, 256, 64000, 1600, 40, 1}; if (value >= 0xF424) { text[0] = 0; return 1; } for (i = 0; i < 6; ++i) text[i] = RAD50TAB[(value / mult[i]) % 40]; text[6] = 0; return 0; } /* == */ Best regards, Christian Gauger-Cosgrove On 19/11/2019, Christian Gauger-Cosgrove wrote: > On 19/11/2019, Dominique Devienne wrote: >> On Tue, Nov 19, 2019 at 2:00 AM Peter da Silva wrote: >>> The return of RADIX-50. >>> >>> https://en.wikipedia.org/wiki/DEC_Radix-50 >> >> Thanks! I might go with this going forward. --DD >> > To make life easier for those desiring to experience the Wonders of > RADIX-50™, if anyone wants I've attached a copy of my implementation > of RAD50 in both the "traditional" 16-bit form, and a 32-bit form. > > The "*enc" functions encode a string into RAD50, and the "*dec" > functions decode. "rad50*" works on a 16-bit value, "xrad50*" on a > 32-bit. > > I leave it as an exercise for the reader to implement a 64-bit function. > > If anyone has ideas of how to improve the functions: Please feel free > to contribute. > > Best regards, > Christian > -- > Christian M. Gauger-Co
Re: [sqlite] Using application_id
On 19/11/2019, Dominique Devienne wrote: > On Tue, Nov 19, 2019 at 2:00 AM Peter da Silva wrote: >> The return of RADIX-50. >> >> https://en.wikipedia.org/wiki/DEC_Radix-50 > > Thanks! I might go with this going forward. --DD > To make life easier for those desiring to experience the Wonders of RADIX-50™, if anyone wants I've attached a copy of my implementation of RAD50 in both the "traditional" 16-bit form, and a 32-bit form. The "*enc" functions encode a string into RAD50, and the "*dec" functions decode. "rad50*" works on a 16-bit value, "xrad50*" on a 32-bit. I leave it as an exercise for the reader to implement a 64-bit function. If anyone has ideas of how to improve the functions: Please feel free to contribute. Best regards, Christian -- Christian M. Gauger-Cosgrove STCKON08DS0 Contact information available upon request. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Using application_id
On Tue, Nov 19, 2019 at 2:00 AM Peter da Silva wrote: > > > If you stick to lower or upper case letters, could encode up to 6 chars > in the app_id. --DD > > The return of RADIX-50. > > https://en.wikipedia.org/wiki/DEC_Radix-50 Thanks! I might go with this going forward. --DD PS: I tend to prefer reusing "old tech" like this, which already has a "known" name, and Wikipedia page, rather that inventing my own similar but poorly-documented-by-comparison scheme. When I'm aware of them that is :) ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Using application_id
> If you stick to lower or upper case letters, could encode up to 6 chars in > the app_id. --DD The return of RADIX-50. https://en.wikipedia.org/wiki/DEC_Radix-50 ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Using application_id
Hi Clemens! Thanks for your fast reply! And/or how can one "register" an application id to prevent collisions? Submit a patch here. In my case, that would be: --- magic.txt.orig 2019-11-18 18:12:00.957789352 +0100 +++ magic.txt 2019-11-18 18:13:13.055463773 +0100 @@ -29,4 +29,7 @@ >68 belong =0x47503130 OGC GeoPackage version 1.0 file - >68 belong =0x45737269 Esri Spatially-Enabled Database - >68 belong =0x4d504258 MBTiles tileset - +>68 belong =0x4d75636b Muckturnier.org tournament database +>>60 belong x\b (Revision %d) - +!:mime application/x-muckturnier >0 string =SQLite SQLite3 database ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Using application_id
On Mon, Nov 18, 2019 at 2:41 PM Clemens Ladisch wrote: > Tobias Leupold wrote: > Apparently, authors or 'private' file formats do not bother to register > their IDs. > Indeed, there's little point, as those are rarely "public". I tend to chose a 4 letter prefix related to the kind of app/report the SQLite DB is for, and use the hexa for each letter to generate the app_id 32-bit integer. If you stick to lower or upper case letters, could encode up to 6 chars in the app_id. --DD ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Using application_id
Tobias Leupold wrote: > In the docs, a magic file is linked ( https://www.sqlite.org/src/ > artifact?ci=trunk&filename=magic.txt ) with "registered" formats. > > Is there another list with "taken" application ids? No. Apparently, authors or 'private' file formats do not bother to register their IDs. > And/or how can one "register" an application id to prevent collisions? Submit a patch here. Regards, Clemens ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Using application_id
Hi list! I recently learned about the PRAGMA application_id feature of SQLite, which is really nice to be able to identify an application-specific SQLite database at the file system level, even with versioning support via the user_version header. SQLite encourages to use an SQLite database as one's application file format, which I do for one of my projects (like probably hundreds of other projects do). In the docs, a magic file is linked ( https://www.sqlite.org/src/ artifact?ci=trunk&filename=magic.txt ) with "registered" formats. With SQLite being so widely used, I can hardly believe that only 6 projects decided to make use of the application_id header until now. So here's my question: Is there another list with "taken" application ids? Some kind of wiki perhaps? And/or how can one "register" an application id to prevent collisions? Thanks for the information in advance! Cheers, Tobias ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users