From 68b1bf06c7736afa27367c443b67a06ba0ed9112 Mon Sep 17 00:00:00 2001 From: Zeex Date: Wed, 3 Sep 2014 19:03:04 +0700 Subject: [PATCH] pawndisasm: Print source code along with disassembly The algorithm isn't the best, but it's simple and it works. --- source/compiler/pawndisasm.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/source/compiler/pawndisasm.c b/source/compiler/pawndisasm.c index 275bbd1..0d25628 100644 --- a/source/compiler/pawndisasm.c +++ b/source/compiler/pawndisasm.c @@ -24,6 +24,7 @@ #include #include #include +#include "sc.h" #include "../amx/amx.h" #include "../amx/amxdbg.h" @@ -442,7 +443,10 @@ int main(int argc,char *argv[]) AMX_DBG dbg; int dbgloaded; const char *filename; - long line,prevline; + long nline,nprevline; + FILE *fpsrc; + int i,j; + char line[sLINEMAX]; if (argc<2 || argc>3) { printf("Usage: pawndisasm [output]\n"); @@ -506,7 +510,7 @@ int main(int argc,char *argv[]) /* browse through the code */ cip=code; codesize=amxhdr.dat-amxhdr.cod; - prevline=-1; + nprevline=-1; while (((unsigned char*)cip-(unsigned char*)code)nprevline) + fputs(line,fplist); + } /* for */ + fclose(fpsrc); + } /* if */ + nprevline=nline; + } /* if */ } /* if */ func=opcodelist[(int)(*cip&0x0000ffff)].func; cip+=func(fplist,cip+1,*cip,(cell)(cip-code)*sizeof(cell));