[AD] dat util diff thingie |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Ho ho... Ok, it turns out I'm a bit unmotivated when it comes to submitting
my little changes to Allegro. Ah well.
I made a modification to the datafile util, it implements recursive
updating ``properly'' via the -r switch. Seems to work good, I'm a tad
hesitant to release it only because I've not tested it for a specific
problem that might be coming up. In particular I think there may be a bug
with it not detecting what needs updating quite properly. While it will
never under-update (that would render it useless), once it comes across one
changed file in a nested datafile I think it might be updating all the
files after that, even though they may not need it. I haven't checked this
specifically because I haven't been motivated enough. Give me a cheer for
finally downloading and installing diff however ;-) I think it only took me
5 people to tell me how to use it and about 1 month sitting around and
thinking about it before I finally bothered heheh. I can't help it, I'm
unix-retarded.
Whew. Anyways bottom line I guess is that it's a tad experimental. In
general however it works very well. I use nested datafiles extensively and
I haven't had it munge anything or crash or anything (ahem! which is more
than I can say for the grabber), and I've been using it for at least a
month. So there you have it. Oh and, I hope I did the diff correctly. The
file that needs changing is /tools/dat.c
- Calvin -
--- dat.c Mon Mar 13 00:23:48 2000
+++ dat-new.c Thu Feb 17 13:08:30 2000
@@ -25,7 +25,7 @@
#include "allegro.h"
#include "datedit.h"
-#if ((defined ALLEGRO_DOS) || (defined ALLEGRO_MSVC)) && (!defined SCAN_DEPEND)
+#if (defined ALLEGRO_DOS) || (defined ALLEGRO_MSVC)
#define HAVE_CONIO_H
#include <conio.h>
#endif
@@ -47,6 +47,7 @@
static int opt_gridy = -1;
static int opt_gridw = -1;
static int opt_gridh = -1;
+static int opt_recursefull = 0;
static char *opt_datafile = NULL;
static char *opt_outputname = NULL;
static char *opt_headername = NULL;
@@ -65,7 +66,7 @@
static int opt_usedname[MAX_FILES];
static int opt_numnames = 0;
-
+static void dat_save(DATAFILE *dat, char *name);
/* display help on the command syntax */
static void usage()
@@ -97,6 +98,7 @@
printf("\t'-u' updates the contents of the datafile\n");
printf("\t'-v' selects verbose mode\n");
printf("\t'-w' always updates the entire contents of the datafile\n");
+ printf("\t'-r' recursively update nested datafiles (experimental; only works with -u or -w)\n");
printf("\t'-007 password' sets the file encryption key\n");
printf("\t'PROP=value' sets object properties\n");
}
@@ -431,6 +433,8 @@
int i;
char *name;
char tmp[256];
+ DATAFILE *sub_datafile;
+ char *sub_name;
for (i=0; dat[i].type != DAT_END; i++) {
name = get_datafile_property(dat+i, DAT_NAME);
@@ -438,10 +442,44 @@
strcat(tmp, name);
if (dat[i].type == DAT_FILE) {
- strcat(tmp, "/");
- do_update((DATAFILE *)dat[i].dat, tmp);
- if (err)
- return;
+ if (opt_recursefull) {
+ /* we first update our sub datafile with the options passed in */
+ sub_name = get_datafile_property(dat+i, DAT_ORIG);
+ if (!*sub_name)
+ {
+ printf("sub datafile %s has no origin data, not recursing\n", name);
+ err = 1;
+ return;
+ }
+ printf("Recursively updating %s\n", sub_name);
+ sub_datafile = datedit_load_datafile(sub_name, FALSE, opt_password);
+ if (!sub_datafile)
+ {
+ err = 1;
+ return;
+ }
+
+ do_update(sub_datafile, "");
+
+ printf("Saving sub datafile %s\n", sub_name);
+ dat_save(sub_datafile, sub_name);
+
+ unload_datafile(sub_datafile);
+
+ /* now we perform a normal datedit_update on it, reading the whole thing in */
+ if ((opt_numnames <= 0) || (is_name(tmp))) {
+ if (!datedit_update(dat+i, opt_verbose, &changed)) {
+ err = 1;
+ return;
+ }
+ }
+ }
+ else {
+ strcat(tmp, "/");
+ do_update((DATAFILE *)dat[i].dat, tmp);
+ if (err)
+ return;
+ }
}
else if ((opt_numnames <= 0) || (is_name(tmp))) {
if (!datedit_update(dat+i, opt_verbose, &changed)) {
@@ -460,6 +498,8 @@
int i;
char *name;
char tmp[256];
+ DATAFILE *sub_datafile;
+ char *sub_name;
for (i=0; dat[i].type != DAT_END; i++) {
name = get_datafile_property(dat+i, DAT_NAME);
@@ -467,10 +507,44 @@
strcat(tmp, name);
if (dat[i].type == DAT_FILE) {
- strcat(tmp, "/");
- do_force_update((DATAFILE *)dat[i].dat, tmp);
- if (err)
- return;
+ if (opt_recursefull) {
+ /* we first update our sub datafile with the options passed in */
+ sub_name = get_datafile_property(dat+i, DAT_ORIG);
+ if (!*sub_name)
+ {
+ printf("sub datafile %s has no origin data, not recursing\n", name);
+ err = 1;
+ return;
+ }
+ printf("Recursively updating %s\n", sub_name);
+ sub_datafile = datedit_load_datafile(sub_name, FALSE, opt_password);
+ if (!sub_datafile)
+ {
+ err = 1;
+ return;
+ }
+
+ do_force_update(sub_datafile, "");
+
+ printf("Saving sub datafile %s\n", sub_name);
+ dat_save(sub_datafile, sub_name);
+
+ unload_datafile(sub_datafile);
+
+ /* now we perform a normal datedit_update on it, reading the whole thing in */
+ if ((opt_numnames <= 0) || (is_name(tmp))) {
+ if (!datedit_force_update(dat+i, opt_verbose, &changed)) {
+ err = 1;
+ return;
+ }
+ }
+ }
+ else {
+ strcat(tmp, "/");
+ do_force_update((DATAFILE *)dat[i].dat, tmp);
+ if (err)
+ return;
+ }
}
else if ((opt_numnames <= 0) || (is_name(tmp))) {
if (!datedit_force_update(dat+i, opt_verbose, &changed)) {
@@ -482,7 +556,6 @@
}
-
/* changes object properties */
static void do_set_props(DATAFILE *dat, char *parentname)
{
@@ -674,6 +747,22 @@
}
+/* save the given datafile based on current options */
+static void dat_save(DATAFILE *dat, char* name)
+{
+ if ((!err) && ((changed) || (opt_compression >= 0) || (opt_strip >= 0)))
+ if (!datedit_save_datafile(dat, name, opt_strip, opt_compression, opt_verbose, TRUE, FALSE, opt_password))
+ err = 1;
+
+ if ((!err) && (opt_headername))
+ if (!datedit_save_header(dat, name, opt_headername, "dat", opt_prefixstring, opt_verbose))
+ err = 1;
+
+ if ((!err) && (opt_dependencyfile))
+ if (!do_save_dependencies(dat, name, opt_dependencyfile))
+ err = 1;
+}
+
int main(int argc, char *argv[])
{
@@ -826,6 +915,10 @@
opt_password = argv[++c];
break;
+ case 'r':
+ opt_recursefull = TRUE;
+ break;
+
default:
printf("Unknown option '%s'\n", argv[c]);
return 1;
@@ -954,17 +1047,7 @@
}
}
- if ((!err) && ((changed) || (opt_compression >= 0) || (opt_strip >= 0)))
- if (!datedit_save_datafile(datafile, opt_datafile, opt_strip, opt_compression, opt_verbose, TRUE, FALSE, opt_password))
- err = 1;
-
- if ((!err) && (opt_headername))
- if (!datedit_save_header(datafile, opt_datafile, opt_headername, "dat", opt_prefixstring, opt_verbose))
- err = 1;
-
- if ((!err) && (opt_dependencyfile))
- if (!do_save_dependencies(datafile, opt_datafile, opt_dependencyfile))
- err = 1;
+ dat_save(datafile, opt_datafile);
unload_datafile(datafile);
}