I've managed to come up with a DFHack tool that untasks all items in the current fortress. You'll need an appropriate compiler to build it for your platform.
// clears the "tasked" flag on all items
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <vector>
using namespace std;
#include <DFHack.h>
#include <dfhack/DFVector.h>
#include <dfhack/DFTypes.h>
int main ()
{
DFHack::Process * p;
unsigned int i;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::memory_info * mem = DF->getMemoryInfo();
p = DF->getProcess();
DFHack::DfVector <uint32_t> p_items (p, p->getDescriptor()->getAddress ("items_vector"));
uint32_t size = p_items.size();
int numtasked = 0;
for (i=0;i<size;i++)
{
DFHack::t_itemflags flags;
flags.whole = p->readDWord(p_items[i] + 0x0C);
if (flags.bits.in_job)
{
flags.bits.in_job = 0;
p->writeDWord(p_items[i] + 0x0C, flags.whole);
numtasked++;
}
}
cout << "Found and untasked " << numtasked << " items." << endl;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}
I embarked, deconstructed my wagon, placed a wood stockpile nearby and ran long enough for the logs to be tasked for hauling (but not long enough for any of them to be picked up), then abandoned. I then reclaimed the fort, reclaimed the logs, then tried to build a wall - it wouldn't let me. After running my tool (and seeing it print "Found and untasked 3 items."), I was able to select the 3 logs as building materials - I didn't wait long enough to see if they would actually be used properly, but I suspect it'd work out in the end. Running the tool in an active fortress would likely have unpredictable results, ranging from "Urist McDwarf cancels task: Job item lost or destroyed" to crashes.