rsrce-0.2.2/0000775000175000017500000000000010463574710012200 5ustar julienjulienrsrce-0.2.2/GPL-20000664000175000017500000004311010454573522012703 0ustar julienjulien GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. rsrce-0.2.2/debian/0000775000175000017500000000000010463574707013430 5ustar julienjulienrsrce-0.2.2/debian/control0000664000175000017500000000156010461550072015020 0ustar julienjulienSource: rsrce Maintainer: Debootloaders miBoot Maintainers Team Uploaders: Sven Luther , Aurélien GÉRÔME , Jeremie Koenig , Piotr Krysiuk Section: otherosfs Priority: optional Build-Depends: debhelper (>= 4) Standards-Version: 3.7.2 Package: rsrce Architecture: any Depends: ${shlibs:Depends} Suggests: hfsutils, macutils Description: editor for Macintosh resource forks Rsrce is an interactive, command-driven Macintosh resource editor. It aims at providing the functionality of the MacOS tool "resedit" on Unix-like systems. . This program hasn't been tested much and should be considered unstable material. It has exclusively been created and used to change the configuration of miBoot files. Please use with care and report any experience. rsrce-0.2.2/debian/compat0000664000175000017500000000000210454574206014620 0ustar julienjulien4 rsrce-0.2.2/debian/rsrce.docs0000664000175000017500000000000710454574206015407 0ustar julienjulienREADME rsrce-0.2.2/debian/changelog0000664000175000017500000000352010461545775015303 0ustar julienjulienrsrce (0.2.2) unstable; urgency=low * Improve the manual page. * Add some command line options to allow for '#!/usr/bin/rsrce -ef' scripts. * A bug prevented file to be read on big-endian architectures; fix provided by Piotr Krysiuk. (closes: #379878) -- Jeremie Koenig Wed, 26 Jul 2006 03:54:33 +0200 rsrce (0.2.1) unstable; urgency=low * Aurélien GÉRÔME - Convert debian/control from ISO_8859-15 to UTF-8. - Fix lintian warnings and errors. - Conform compiler optimisations to policy. * Jérémie Koenig - Fix the type list offset in the map header which points to the number of types field before the actual list. - Fix the written resource map length which included space for non-existant names. -- Aurélien GÉRÔME Sat, 15 Jul 2006 15:33:40 +0200 rsrce (0.2) unstable; urgency=low * Aurélien GÉRÔME - Fix exporting of binary resources, courtesy of Piotr Krysiuk (closes: #340533). - New feature by Piotr Krysiuk: rsrce now allows for new resources to be created (closes: #365655). - Update to the latest Standards-Version. * Jérémie Koenig - No more crazy memory management in resource.c. - Fix /tmp clutter, behaviour with empty strings and some crashes on malformed input. - Command parser with backslashes, single quotes and comments. -- Jeremie Koenig Wed, 12 Jul 2006 09:46:57 +0200 rsrce (0.1-2) unstable; urgency=low * Added man page provided by Jeremie Koenig. -- Sven Luther Fri, 26 Mar 2004 20:55:41 +0100 rsrce (0.1-1) unstable; urgency=low * Initial release (closes: #237308) -- Jeremie Koenig Thu, 4 Mar 2004 11:59:33 +0100 rsrce-0.2.2/debian/copyright0000664000175000017500000000245110456166721015360 0ustar julienjulienRsrce has originally been written by Jérémie Koenig and is now maintained within the Debootloaders project . It is primarily distributed as a native Debian package. The authors can be contacted by email using this address: Debootloaders miBoot Maintainers Here is the copyright notice: /* rsrce -- a Macintosh resource fork editor * Copyright (C) 2004 Jeremie Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ On Debian systems, the GNU General Public License is available as the /usr/share/common-licenses/GPL file. rsrce-0.2.2/debian/rules0000775000175000017500000000070610456203023014471 0ustar julienjulien#!/usr/bin/make -f build: stamp.build stamp.build: dh_testdir make touch $@ binary: binary-arch binary-indep binary-indep: binary-arch: stamp.build dh_testdir dh_testroot dh_clean dh_installdirs $(MAKE) install DESTDIR=debian/rsrce LOCAL= dh_installdocs dh_installman rsrce.1 dh_installchangelogs dh_strip dh_fixperms dh_compress dh_shlibdeps dh_gencontrol dh_builddeb clean: dh_testdir dh_clean rm -f stamp.build $(MAKE) clean rsrce-0.2.2/debian/rsrce.dirs0000664000175000017500000000001010454574206015412 0ustar julienjulienusr/bin rsrce-0.2.2/translate.h0000664000175000017500000000216710454573522014354 0ustar julienjulien/* rsrce -- a Macintosh resource fork editor * Copyright (C) 2004 Jeremie Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __TRANSLATE_H__ #define __TRANSLATE_H__ #include #include "resource.h" struct translator *tr_lookup(struct resource *r, const char *ext); const char *tr_ext(struct translator *t); int tr_export(struct translator *t, struct resource *r, FILE *o); int tr_import(struct translator *t, struct resource *r, FILE *i); #endif rsrce-0.2.2/rsrc-fmt.h0000664000175000017500000000147410455051366014112 0ustar julienjulien /* Resource header */ struct reshdr { uint32_t dofs, mofs, dlen, mlen; }; /* Resource map header */ struct resmaphdr { uint8_t reserved[22]; uint16_t attr; uint16_t tlistofs; uint16_t nlistofs; uint16_t tnum; }; /* Resource type list entry */ struct restype { restype_t type; uint16_t rnum; uint16_t refofs; }; /* Resource reference list entry */ struct resref { uint16_t id; uint16_t nameofs; unsigned int attr:8, dataofs:24; uint32_t reserved; }; /* Resource name list entry */ struct resname { uint8_t len; char name[0]; }; /* Resource data */ struct resdata { uint32_t len; uint8_t data[0]; }; /* Useful macros for the 3-bytes data offset */ #if __BYTE_ORDER == __LITTLE_ENDIAN #define ntoh3(a) (ntohl(a) >> 8) #define hton3(a) (htonl(a) >> 8) #else #define ntoh3(a) (a) #define hton3(a) (a) #endif rsrce-0.2.2/config.h0000664000175000017500000000165410454574324013625 0ustar julienjulien/* rsrce -- a Macintosh resource fork editor * Copyright (C) 2004 Jeremie Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* config.h: configuration macros */ #define CFG_EDITOR "/usr/bin/sensible-editor" #define CFG_BUFSZ 1024 #define CFG_PROMPT "rsrce> " rsrce-0.2.2/README0000664000175000017500000000427010454573522013063 0ustar julienjulienHow to use rsrce 1. Introduction This is rsrce, a Macintosh resource fork editor for Unix-like operating systems. It has been originally created to change the configuration of the miBoot Linux bootloader for OldWorld PowerMac computers. Since I do not use MacOS, I haven't tested any other usage of this program. You should therefore be very careful when using it, as it could very well produce unusable output. Consider this as unstable software. Another consequence of this is wildly missing functionnality. I'm not going to work on it, since I couldn't test anything in a real situation. Patches and/or bug reports would be very welcome. 2. Overview Rsrce acts on raw resource forks stored in Unix files, such as .rsrc files produced by the hexbin command (from the macutil package.) You read such a thing into memory using the "read" command, then act on the resources it contains, then write it back. Resources are referred to by specifing their type and id, separated by a colon. I mean, something like "STR#:128". If the type field contains less than 4 letters, spaces are added to complete it. Rsrce doesn't allow you to edit the resource data directly. It only knows to import/export them from/to files, performing conversion for the few resource types it knows. The "edit" command exports some resource's data to a temporary file, invokes and external editor, then import the file back. 3. Commands read reads the resources from write write the resources to ls lists resources (type, id, attributes, data lenght, name) hexdump shows and hexdump of 's data import|export import/export 's data from/to edit invoke an external editor to change 's data help lists available commands exit exits (without saving, use write before exit if you wish to save your changes). 4. Conclusion If you actually use this program, please let me know how it's going. If you hack it, please send me your patches. Be careful not to hack it too much, however, you'd take the risk of becoming its maintainer. Jeremie Koenig 2004-03-04 rsrce-0.2.2/command.c0000664000175000017500000002006010456215154013754 0ustar julienjulien/* rsrce -- a Macintosh resource fork editor * Copyright (C) 2004 Jeremie Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include "config.h" #include "resource.h" #include "translate.h" #include "command.h" static struct res_fork *cmd_rf; static restype_t cmd_res_type; static int cmd_res_id; static struct resource *cmd_res; int cmd_parseresource(const char *spec) { char *colon; if(!spec) { fprintf(stderr, "Please specify a resource to act on.\n"); return 1; } colon = strrchr(spec, ':'); if(!colon || colon > spec+4) { fprintf(stderr, "Incorrect resource specification\n"); return 1; } memset(cmd_res_type, ' ', sizeof(cmd_res_type)); memcpy(cmd_res_type, spec, colon - spec); cmd_res_id = atoi(colon + 1); return 0; } int cmd_selectresource(const char *spec) { if(cmd_parseresource(spec)) return 1; cmd_res = res_lookup(cmd_rf, cmd_res_type, cmd_res_id); if(!cmd_res) { fprintf(stderr, "No such resource.\n"); return 1; } return 0; } static char *cmd_ifname, *cmd_ofname; int cmd_read(char **argv) { struct res_fork *rf; if(argv[1]) { cmd_ifname = realloc(cmd_ifname, strlen(argv[1]) + 1); strcpy(cmd_ifname, argv[1]); } if(!cmd_ifname) { fprintf(stderr, "Read which file ?\n"); return 1; } rf = res_read(cmd_ifname); if(!rf) { fprintf(stderr, "Error while reading %s\n", argv[1]); return 1; } res_delfork(cmd_rf); cmd_rf = rf; return 0; } int cmd_write(char **argv) { const char *fname; int ret; if(argv[1]) { cmd_ofname = realloc(cmd_ofname, strlen(argv[1]) + 1); strcpy(cmd_ofname, argv[1]); } fname = cmd_ofname ? cmd_ofname : cmd_ifname; if(!fname) { fprintf(stderr, "Write to which file ?\n"); return 1; } ret = res_write(cmd_rf, fname); if(ret < 0) { fprintf(stderr, "Write error\n"); return 1; } return 0; } int cmd_create(char **argv) { if(!argv[1]) { fprintf(stderr, "%s \n", argv[0]); return 1; } if(cmd_parseresource(argv[1])) return 1; cmd_res = res_lookup(cmd_rf, cmd_res_type, cmd_res_id); if(cmd_res) { fprintf(stderr, "Resource already exists.\n"); return 1; } cmd_res = res_new(cmd_rf, cmd_res_type, cmd_res_id); return 0; } int cmd_delete(char **argv) { if(!argv[1]) { fprintf(stderr, "%s \n", argv[0]); return 1; } if(cmd_selectresource(argv[1])) return 1; res_delete(cmd_res); return 0; } int cmd_rename(char **argv) { if(!argv[2]) { fprintf(stderr, "%s \n", argv[0]); return 1; } if(cmd_selectresource(argv[1])) return 1; res_rename(cmd_res, argv[2], strlen(argv[2])); return 0; } int cmd_chattr(char **argv) { if(!argv[2]) { fprintf(stderr, "%s \n", argv[0]); return 1; } if(cmd_selectresource(argv[1])) return 1; res_chattr(cmd_res, argv[2]); return 0; } int cmd_ls(char **argv) { res_ls(stdout, cmd_rf); return 0; } int cmd_hexdump(char **argv) { int i, j; unsigned char *data; int len; if(cmd_selectresource(argv[1])) return 1; res_getdata(cmd_res, (void **) &data, &len); for(i=0 ; i < len ; i += 16) { printf("%8x ", i); for(j=0 ; j < 16 ; j++) { if(i+j < len) printf(" %02x", data[i+j]); else printf(" "); } printf(" |"); for(j=0 ; j < 16 && i+j < len ; j++) printf("%c", isprint(data[i+j]) ? data[i+j] : '.'); printf("|\n"); } return 0; } int cmd_export(char **argv) { struct translator *tr; FILE *f; char *c; int what, r; what = (strcmp(argv[0], "export") == 0); if(!argv[2]) { fprintf(stderr, "%s []\n", argv[0]); return 1; } if(!argv[3]) { c = strrchr(argv[2], '.'); argv[3] = c ? c+1 : NULL; } if(cmd_selectresource(argv[1])) return 1; tr = tr_lookup(cmd_res, argv[3]); if(!tr) { fprintf(stderr, "I don't know how to translate this.\n"); return 1; } f = (strcmp(argv[2], "-") == 0) ? (what ? stdout : stdin) : fopen(argv[2], what ? "w" : "r"); if(!f) { perror(argv[2]); return 1; } r = (what ? tr_export : tr_import)(tr, cmd_res, f); if(strcmp(argv[2], "-") != 0) fclose(f); return r; } /* Export the resource data to a temporary file and return its name */ static char *cmd_edit_export(struct translator *tr) { char filename[] = "/tmp/rsrce.XXXXXX", *nfname, *ret = NULL; const char *ext; int fd, r; FILE *f = NULL; fd = mkstemp(filename); if(fd < 0) { perror(filename); return NULL; } ext = tr_ext(tr); nfname = malloc(strlen(filename) + strlen(ext) + 2); sprintf(nfname, "%s.%s", filename, ext); if((r = rename(filename, nfname)) < 0) perror(nfname); else if((f = fdopen(fd, "w")) == NULL) perror("fdopen"); else if(tr_export(tr, cmd_res, f) < 0) fprintf(stderr,"Couldn't translate resource data\n"); else ret = nfname; if(!ret) { unlink(r < 0 ? filename : nfname); free(nfname); } if(f) fclose(f); else close(fd); return ret; } /* Invoke the external editor */ static int cmd_edit_edit(const char *fname) { char *cmd; int ret; /* FIXME: We should fork and exec rather than system in order to avoid * shell interference with funny filenames. */ cmd = malloc(strlen(CFG_EDITOR) + strlen(fname) + 2); sprintf(cmd, "%s %s", CFG_EDITOR, fname); ret = system(cmd); free(cmd); return ret; } /* Re-import the resource data */ static int cmd_edit_import(struct translator *tr, const char *filename) { FILE *f; int ret; f = fopen(filename, "r"); if(!f) { perror(filename); return -1; } ret = tr_import(tr, cmd_res, f); fclose(f); return ret; } int cmd_edit(char **argv) { struct translator *tr; int ret; char *fname; if(cmd_selectresource(argv[1]) != 0) return 1; tr = tr_lookup(cmd_res, argv[2]); if(!tr) { fprintf(stderr, "I don't know how to translate this.\n"); return 1; } fname = cmd_edit_export(tr); if(!fname) return 1; ret = (cmd_edit_edit(fname) == 0 && cmd_edit_import(tr, fname) == 0); unlink(fname); free(fname); return ret ? 0 : 1; } int cmd_help(char **argv); int cmd_exit(char **argv) { exit(0); } struct command { const char *cmd; int (*f)(char **argv); const char *help; } cmd_table[] = { {"read", cmd_read, "Read the resource fork from a file"}, {"write", cmd_write, "Write the resource fork to a file"}, {"create", cmd_create, "Create resource"}, {"delete", cmd_delete, "Delete resource"}, {"rename", cmd_rename, "Change the resource name"}, {"chattr", cmd_chattr, "Change the resource attributes"}, {"ls", cmd_ls, "List resources"}, {"hexdump", cmd_hexdump, "Show an hexdump of the resource data"}, {"import", cmd_export, "Import resource data from a file"}, {"export", cmd_export, "Export resource data to a file"}, {"edit", cmd_edit, "Edit resource data"}, {"help", cmd_help, "This short help listing"}, {"exit", cmd_exit, "Exit (don't forget to write first!)"}, {NULL, NULL, NULL} }; int cmd_help(char **argv) { int i; for(i=0 ; cmd_table[i].cmd ; i++) { printf("%10s -- %s\n", cmd_table[i].cmd, cmd_table[i].help); } return 0; } int cmd_exec(char **argv) { int i; if(!argv[0]) return 0; for(i=0 ; cmd_table[i].cmd ; i++) { if(strcmp(cmd_table[i].cmd, argv[0]) == 0) return cmd_table[i].f(argv); } fprintf(stderr, "%s: no such command\n", argv[0]); return 1; } void cmd_init(const char *ifname, const char *ofname) { cmd_ifname = ifname ? strdup(ifname) : NULL; cmd_ofname = ofname ? strdup(ofname) : NULL; cmd_rf = cmd_ifname ? res_read(cmd_ifname) : res_newfork(); if(!cmd_rf) { exit(1); } } rsrce-0.2.2/command.h0000664000175000017500000000165210456215154013767 0ustar julienjulien/* rsrce -- a Macintosh resource fork editor * Copyright (C) 2004 Jeremie Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __COMMAND_H__ #define __COMMAND_H__ int cmd_exec(char **argv); void cmd_init(const char *ifname, const char *ofname); #endif rsrce-0.2.2/main.c0000664000175000017500000000647110456215154013274 0ustar julienjulien/* rsrce -- a Macintosh resource fork editor * Copyright (C) 2004 Jeremie Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include "config.h" #include "command.h" #define MAXCMDSZ 1023 #define MAXARGC 7 /* Command parser */ static char backslashed(char c) { static const char bsc[] = "abfnrtv", bse[] = "\a\b\f\n\r\t\v"; char *bsi; return (bsi = strchr(bsc, c)) ? bse[bsi - bsc] : c; } static int parse_command(FILE *f) { char buf[MAXCMDSZ+1], *argv[MAXARGC+1]; int ok = 1, pos = 0, argc = 0, c; enum { BOA, UNQUOTED, QUOTED, BACKSLASHED, COMMENT, EOC } state = BOA; while(state != EOC && (c = fgetc(f)) > 0) { if(pos >= MAXCMDSZ || argc >= MAXARGC) ok = 0, pos = 0, argc = 0; switch(state) { case BOA: if(c == '#') { state = COMMENT; break; } if(c == '\n') { state = EOC; break; } if(isspace(c)) { break; } argv[argc++] = buf + pos; state = UNQUOTED; case UNQUOTED: if(c == '\n') { state = EOC; break; } if(isspace(c)) { buf[pos++]='\0'; state=BOA; break; } if(c == '\\') { state = BACKSLASHED; break; } if(c == '\'') { state = QUOTED; break; } case QUOTED: if(c == '\'') { state = UNQUOTED; break; } buf[pos++] = c; break; case BACKSLASHED: buf[pos++] = backslashed(c); state = UNQUOTED; break; case COMMENT: if(c == '\n') { state = EOC; break; } break; } } buf[pos] = '\0'; argv[argc] = NULL; if(!ok) { fprintf(stderr, "Max lenght of commands: %d!\n", MAXCMDSZ); return -1; } return cmd_exec(argv); } /* Command line options */ static struct { FILE *cmdin; int e; const char *ifname, *ofname; } opts; static void usage(const char *myname) { fprintf(stderr, "Usage: %s [-e] [-f