[Debootloaders-devel] r66 - trunk/rsrce
Aurélien GÉRÔME
ag-guest at costa.debian.org
Tue Jul 11 01:22:31 UTC 2006
Author: ag-guest
Date: 2006-07-11 01:22:31 +0000 (Tue, 11 Jul 2006)
New Revision: 66
Modified:
trunk/rsrce/command.c
trunk/rsrce/resource.h
Log:
Patch from Piotr Krysiuk to add new commands to create and delete
resource, change resource name and attributes.
Modified: trunk/rsrce/command.c
===================================================================
--- trunk/rsrce/command.c 2006-07-11 01:19:57 UTC (rev 65)
+++ trunk/rsrce/command.c 2006-07-11 01:22:31 UTC (rev 66)
@@ -27,12 +27,12 @@
#include "command.h"
struct res_fork *cmd_rf;
+restype_t cmd_res_type;
+int cmd_res_id;
struct resource *cmd_res;
-int cmd_selectresource(const char *spec)
+int cmd_parseresource(const char *spec)
{
- restype_t type;
- int id;
char *colon;
if(!spec) {
@@ -45,10 +45,19 @@
fprintf(stderr, "Incorrect resource specification\n");
return 1;
}
- memset(type, ' ', sizeof(type));
- memcpy(type, spec, colon - spec);
- id = atoi(colon + 1);
- cmd_res = res_lookup(cmd_rf, type, id);
+ 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;
@@ -108,6 +117,68 @@
return 0;
}
+int cmd_create(char **argv)
+{
+ if(!argv[1]) {
+ fprintf(stderr, "%s <resource>\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 <resource>\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 <resource> <name>\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 <resource> <attributes>\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);
@@ -277,6 +348,10 @@
} 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"},
Modified: trunk/rsrce/resource.h
===================================================================
--- trunk/rsrce/resource.h 2006-07-11 01:19:57 UTC (rev 65)
+++ trunk/rsrce/resource.h 2006-07-11 01:22:31 UTC (rev 66)
@@ -30,6 +30,7 @@
void res_setdata(struct resource *r, void *p, int len);
void res_gettype(struct resource *r, restype_t type);
void res_settype(struct resource *r, restype_t type);
+void res_rename(struct resource *r, char *name, int nlen);
void res_chattr(struct resource *r, const char *spec);
void res_delete(struct resource *r);
More information about the Debootloaders-devel
mailing list