* debugger/mcs51/break.c, debugger/mcs51/cmd.c,
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 20 Dec 2008 00:34:55 +0000 (00:34 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 20 Dec 2008 00:34:55 +0000 (00:34 +0000)
  debugger/mcs51/simi.c, debugger/mcs51/symtab.c,
  support/cpp/libcpp/macro.c: fix format string errors

* sim/ucsim/s51.src/timer2.cc: add clarifying parens

* src/pic/device.c: partial rewrite using strtok,
  quieten compiler warnings, adopt SDCC coding style

* as/link/hc08/lkelf.c, as/link/lkaomf51.c, as/link/lklibr.c,
  as/link/z80/lkgb.c, as/z80/asout.c, debugger/mcs51/cmd.c,
  sim/ucsim/utils.cc, src/SDCCasm.c, support/Util/dbuf_string.c,
  support/cpp/c-ppoutput.c, support/cpp/libcpp/lex.c,
  support/librarian/sdcclib.c, support/makebin/makebin.c:
  quieten most compiler warnings

* sim/ucsim/avr.src/arith_inst.cc: quieten compiler warnings,
  probably fix operator precedence bug

* doc/clean.mk: quieten rm if no .lyx is present

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5293 4a8a32a2-be11-0410-ad9d-d568d2c75423

22 files changed:
ChangeLog
as/link/hc08/lkelf.c
as/link/lkaomf51.c
as/link/lklibr.c
as/link/z80/lkgb.c
as/z80/asout.c
debugger/mcs51/break.c
debugger/mcs51/cmd.c
debugger/mcs51/simi.c
debugger/mcs51/symtab.c
doc/clean.mk
sim/ucsim/avr.src/arith_inst.cc
sim/ucsim/s51.src/timer2.cc
sim/ucsim/utils.cc
src/SDCCasm.c
src/pic/device.c
support/Util/dbuf_string.c
support/cpp/c-ppoutput.c
support/cpp/libcpp/lex.c
support/cpp/libcpp/macro.c
support/librarian/sdcclib.c
support/makebin/makebin.c

index cd9cee3a5fbb92171cc8976baa05a8450c76b2e6..9afc3e2b367b23c4181badef0277ade67d600400 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,32 @@
+2008-12-20 Raphael Neider <rneider AT web.de>
+
+       * debugger/mcs51/break.c, debugger/mcs51/cmd.c,
+         debugger/mcs51/simi.c, debugger/mcs51/symtab.c,
+         support/cpp/libcpp/macro.c: fix format string errors
+
+       * sim/ucsim/s51.src/timer2.cc: add clarifying parens
+
+       * src/pic/device.c: partial rewrite using strtok,
+         quieten compiler warnings, adopt SDCC coding style
+
+       * as/link/hc08/lkelf.c, as/link/lkaomf51.c, as/link/lklibr.c,
+         as/link/z80/lkgb.c, as/z80/asout.c, debugger/mcs51/cmd.c,
+         sim/ucsim/utils.cc, src/SDCCasm.c, support/Util/dbuf_string.c,
+         support/cpp/c-ppoutput.c, support/cpp/libcpp/lex.c,
+         support/librarian/sdcclib.c, support/makebin/makebin.c:
+         quieten most compiler warnings
+
+       * sim/ucsim/avr.src/arith_inst.cc: quieten compiler warnings,
+         probably fix operator precedence bug
+
+       * doc/clean.mk: quieten rm if no .lyx is present
+
 2008-12-19 Borut Razem <borut.razem AT siol.net>
 
        * doc/sdccman.lyx, doc/random-notes.txt, doc/avr/avr_design.txt,
          doc/TININative.txt, doc/macro-sys-design.txt, doc/libdoc.txt,
          doc/README.txt, doc/test_suite_spec.lyx:
-         applaid patch 2446381: Dcoumentation spelling correcitons
+         applied patch 2446381: Dcoumentation spelling correcitons
          thanks to Steven Borley
 
 2008-12-16 Raphael Neider <rneider AT web.de>
index 3cc602fd483de07718419311c0c42af01075ddd5..d37bfa514c5e3752ffe18da119c86702ed8bd7df 100644 (file)
@@ -18,6 +18,7 @@
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 -------------------------------------------------------------------------*/
 
+#include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
@@ -480,6 +481,7 @@ elfGenerateAbs (struct area *ap, listHeader * segments, listHeader * sections)
   Elf32_Word size;
   Elf32_Phdr * phdrp;
   Elf32_Shdr * shdrp;
+  size_t res;
 
   if (!ap->a_image)
     {
@@ -537,7 +539,8 @@ elfGenerateAbs (struct area *ap, listHeader * segments, listHeader * sections)
       shdrp->sh_entsize = 0;
       listAdd (sections, shdrp);
       
-      fwrite (&ap->a_image[addr-ap->a_addr], 1, size, ofp);
+      res = fwrite (&ap->a_image[addr-ap->a_addr], 1, size, ofp);
+      assert(res == size);
     }  
 }
 
@@ -549,6 +552,7 @@ elfGenerateRel (struct area *ap, listHeader * segments, listHeader * sections)
 {
   Elf32_Phdr * phdrp;
   Elf32_Shdr * shdrp;
+  size_t res;
   
   if (!ap->a_image)
     {
@@ -590,7 +594,8 @@ elfGenerateRel (struct area *ap, listHeader * segments, listHeader * sections)
   shdrp->sh_entsize = 0;
   listAdd (sections, shdrp);
   
-  fwrite (ap->a_image, 1, ap->a_size, ofp);
+  res = fwrite (ap->a_image, 1, ap->a_size, ofp);
+  assert(res == ap->a_size);
 }
 
 /*--------------------------------------------------------------------------*/
index 80284782c1044765bb1c6f4e02ad5d4ae66735ef..7a52f4efd4034c00bfe7c628379e23acc43e2860 100644 (file)
@@ -18,6 +18,7 @@
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 -------------------------------------------------------------------------*/
 
+#include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
@@ -199,8 +200,10 @@ void FreeAll(void)
 
 void OutputByte(unsigned char value)
 {
+       size_t res;
        GlobalChkSum+=value;
-       fwrite( &value, 1, 1, aomf51out );
+       res = fwrite( &value, 1, 1, aomf51out );
+       assert(res == 1);
 }
 
 void OutputWord(int value)
@@ -567,7 +570,9 @@ void CollectInfoFromCDB(void)
        CurrentModule=0; /*Set the active module as the first one*/
        while(!feof(CDBin))
        {
-               fgets(buff, sizeof(buff)-1, CDBin);
+               char *res;
+               res = fgets(buff, sizeof(buff)-1, CDBin);
+               assert(res == buff);
 
                if(!feof(CDBin)) switch(buff[0])
                {
index 31d2e897aa472176a5facd25e961d6a9cac5204a..b56340a9b0ee51facf88811c2d3ea0caf2e64693 100644 (file)
@@ -22,6 +22,7 @@
 #define EQ(A,B) !strcmp((A),(B))
 #define MAXLINE 254 /*when using fgets*/
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -392,6 +393,7 @@ void LoadRel(char * libfname, FILE * libfp, char * ModName)
 {
     char str[NINPUT+2];
     int state=0;
+    char *res;
 
     while (fgets(str, NINPUT, libfp) != NULL)
     {
@@ -402,7 +404,8 @@ void LoadRel(char * libfname, FILE * libfp, char * ModName)
             case 0:
                 if(EQ(str, "<FILE>"))
                 {
-                    fgets(str, NINPUT, libfp);
+                    res = fgets(str, NINPUT, libfp);
+                    assert(res == str);
                     str[NINPUT+1] = '\0';
                     chop_crlf(str);
                     if(EQ(str, ModName)) state=1;
@@ -438,7 +441,9 @@ int LoadAdb(FILE * libfp)
 
     while (fgets(str, MAXLINE, libfp) != NULL)
     {
-        str[NINPUT+1] = '\0';
+        if (NINPUT < MAXLINE)
+            str[NINPUT+1] = '\0';
+
         chop_crlf(str);
         switch(state)
         {
@@ -467,11 +472,13 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
     char FLine[MAXLINE+1];
     int state=0;
     long IndexOffset=0, FileOffset;
+    char *res;
 
     while(!feof(libfp))
     {
         FLine[0]=0;
-        fgets(FLine, MAXLINE, libfp);
+        res = fgets(FLine, MAXLINE, libfp);
+        assert(res == FLine);
         chop_crlf(FLine);
 
         switch(state)
@@ -481,7 +488,8 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
                 {
                     /*The next line has the size of the index*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     IndexOffset=atol(FLine);
                     state=1;
@@ -493,7 +501,8 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
                     /*The next line has the name of the module and the offset
                     of the corresponding embedded file in the library*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     sscanf(FLine, "%s %ld", ModName, &FileOffset);
                     state=2;
@@ -738,8 +747,11 @@ int fndsym( char *name )
                     for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
                     for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
 #else
-                    realpath(FirstFound->libspc, absPath1);
-                    realpath(ThisLibr->libspc, absPath2);
+                    char *res;
+                    res = realpath(FirstFound->libspc, absPath1);
+                    assert(res == absPath1);
+                    res = realpath(ThisLibr->libspc, absPath2);
+                    assert(res == absPath2);
 #endif
                     if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
                     {
@@ -771,11 +783,13 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir
     int state=0;
     long IndexOffset=0, FileOffset;
     pmlibrarysymbol ThisSym = NULL;
+    char *res;
 
     while(!feof(libfp))
     {
         FLine[0]=0;
-        fgets(FLine, MAXLINE, libfp);
+        res = fgets(FLine, MAXLINE, libfp);
+        assert(res == FLine);
         chop_crlf(FLine);
 
         switch(state)
@@ -785,7 +799,8 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir
                 {
                     /*The next line has the size of the index*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     IndexOffset=atol(FLine);
                     state=1;
@@ -797,7 +812,8 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir
                     /*The next line has the name of the module and the offset
                     of the corresponding embedded file in the library*/
                     FLine[0]=0;
-                    fgets(FLine, MAXLINE, libfp);
+                    res = fgets(FLine, MAXLINE, libfp);
+                    assert(res == FLine);
                     chop_crlf(FLine);
                     sscanf(FLine, "%s %ld", ModName, &FileOffset);
                     state=2;
index 55ae41ff7b020bc64f88c3742f8a5f5681c0edf2..fca7cd1e0c46f3096e69ddb595d3da2fad8a1079 100644 (file)
@@ -6,6 +6,7 @@
 
 #ifdef GAMEBOY
 
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -182,8 +183,11 @@ VOID gb(int in)
     cart[0x014E/SEGSIZE][0x014E%SEGSIZE] = (unsigned char)((chk>>8)&0xFF);
     cart[0x014F/SEGSIZE][0x014F%SEGSIZE] = (unsigned char)(chk&0xFF);
 
-    for(i = 0; i < NBSEG; i++)
-      fwrite(cart[i], 1, SEGSIZE, ofp);
+    for(i = 0; i < NBSEG; i++) {
+      size_t res;
+      res = fwrite(cart[i], 1, SEGSIZE, ofp);
+      assert(res == SEGSIZE);
+    }
   }
 }
 
index 5d756469001fc1061bddb0454b58e734de1e774a..df9254e620570b45e6e8bcdf8ae9674c07b9070f 100644 (file)
@@ -611,7 +611,7 @@ outbuf(char *s)
                 fprintf(ofp, "T");
                 out(txt,(int) (txtp-txt));
                 fprintf(ofp, "\n");
-                fprintf(ofp, s);
+                fprintf(ofp, "%s", s);
                 out(rel,(int) (relp-rel));
                 fprintf(ofp, "\n");
         }
index 1cf6252293e8ce513eb857a3e80f5d624733a8e4..0637661932aaf1ad4edf63fe4384114dfa1cd90a 100644 (file)
@@ -469,7 +469,7 @@ BP_CALLBACK(fexitCB)
     /* check main function */
     if ( !strcmp(func->sym->name, "main"))
     {
-        fprintf(stdout, "Program exited with code %d.\n", simGetValue (0x82,'I',2));
+        fprintf(stdout, "Program exited with code %lu.\n", simGetValue (0x82,'I',2));
         return 1;
     }
     return 0;
index 840a57a400f28a5491686373acb84282776602b6..332ee2edaf58b512ee4345debeefa27c9b9f4dd6 100644 (file)
@@ -21,6 +21,7 @@
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <assert.h>
 #include "sdcdb.h"
 #include "symtab.h"
 #include "simi.h"
@@ -903,7 +904,7 @@ static int cmdDisasm (char *s, context *cctxt, int args)
     else
     {
         if ( args > 1 )
-            printf("Dump of assembler code from 0x%08x to 0x%08x:\n",saddr,eaddr);
+            printf("Dump of assembler code from 0x%08lx to 0x%08lx:\n",saddr,eaddr);
         found = 0;
         while ( saddr < eaddr )
         {
@@ -1011,11 +1012,11 @@ static int commonSetUserBp(char *s, context *cctxt, char bpType)
             module *modul;
             if (!applyToSet(modules,moduleLineWithAddr,braddr,&modul,&line))
             {
-                fprintf(stderr,"Address 0x%08x not exists in code.\n",braddr);
+                fprintf(stderr,"Address 0x%08lx not exists in code.\n",braddr);
             }
             else
             {
-                Dprintf(D_break, ("commonSetUserBp: g) addr:%x \n",braddr));
+                Dprintf(D_break, ("commonSetUserBp: g) addr:%lx \n",braddr));
                 setBreakPoint ( braddr , CODE , bpType , userBpCB ,
                             modul->c_name,line);
             }
@@ -1409,9 +1410,12 @@ int cmdDelUserBp (char *s, context *cctxt)
     if (!*s ) {
         if (userBpPresent) {
             char buffer[10];
+            char *res;
+
             fprintf (stdout,"Delete all breakpoints? (y or n) ");
             fflush(stdout);
-            fgets(buffer,sizeof(buffer),stdin);
+            res = fgets(buffer,sizeof(buffer),stdin);
+            assert(res == &buffer[0]);
             if (toupper(buffer[0]) == 'Y')
                 deleteUSERbp(-1);
         }
@@ -1632,13 +1636,15 @@ int cmdRun (char *s, context *cctxt)
     resetHitCount();
         simGo(0);
     } else {
+        char *res;
 
         fprintf(stdout,
                 "The program being debugged has been started already.\n");
         fprintf(stdout,"Start it from the beginning? (y or n) ");
         fflush(stdout);
 
-        fgets(buff,sizeof(buff),stdin);
+        res = fgets(buff,sizeof(buff),stdin);
+        assert(res == &buff[0]);
         if (toupper(buff[0]) == 'Y') {
             simReset();
         resetHitCount();
@@ -1927,17 +1933,17 @@ static void infoRegisters( int all, context *ctxt)
     for ( j = 0; j < 8 ; j++ )
     {
         val = simGetValue (j,'R',1);
-        fprintf(stdout," 0x%02X",val);
+        fprintf(stdout," 0x%02lX",val);
     }
     fprintf(stdout,"\n");
     val = simGetValue (0xe0,'I',1);
-    fprintf(stdout,"ACC : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.'));
+    fprintf(stdout,"ACC : 0x%02lX %lu %c\n",val,val,(isprint(val) ? (char)val : '.'));
     val = simGetValue (0xf0,'I',1);
-    fprintf(stdout,"B   : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.'));
+    fprintf(stdout,"B   : 0x%02lX %lu %c\n",val,val,(isprint(val) ? (char)val : '.'));
     val = simGetValue (0x82,'I',2);
-    fprintf(stdout,"DPTR: 0x%04X %d\n",val,val);
+    fprintf(stdout,"DPTR: 0x%04lX %lu\n",val,val);
     val = simGetValue (0x81,'I',1);
-    fprintf(stdout,"SP  : 0x%02X (0x%04X)\n",val,simGetValue (val-1,'B',2));
+    fprintf(stdout,"SP  : 0x%02lX (0x%04lX)\n",val,simGetValue (val-1,'B',2));
     fprintf(stdout,"PSW : 0x%02X | CY : %c | AC : %c | OV : %c | P : %c\n",
             i,(i&0x80)?'1':'0',(i&0x40)?'1':'0',(i&4)?'1':'0',(i&1)?'1':'0');
     if ( all )
@@ -1956,7 +1962,7 @@ static void infoRegisters( int all, context *ctxt)
             if (applyToSetFTrue(sfrsymbols,symWithAddr,i,'I',&sym))
             {
                 val = simGetValue (sym->addr,sym->addrspace,sym->size);
-                fprintf(stdout,"%s : 0x%02x",sym->name,val);
+                fprintf(stdout,"%s : 0x%02lx",sym->name,val);
                 if ( !(i & 0x07 ))
                 {
                     for ( j = 0 ; j < 8 ; j++ )
@@ -2480,7 +2486,7 @@ static void printValBasic(symbol *sym, link *type,
         fprintf(stdout,"%f",v.f);
     else
         if (IS_PTR(type))
-            fprintf(stdout,"0x%*x",size<<1,v.val);
+            fprintf(stdout,"0x%*lx",size<<1,v.val);
         else
         if (IS_INTEGRAL(type))
         {
@@ -2516,11 +2522,11 @@ static void printValBasic(symbol *sym, link *type,
                     if (IS_BITVAR(etype))
                         fprintf(stdout,"%c",(v.val?'1':'0'));
                     else
-                        fprintf(stdout,"0x%0*x",size<<1,v.val);
+                        fprintf(stdout,"0x%0*lx",size<<1,v.val);
                 }
             }
             } else
-            fprintf(stdout,"0x%0*x",size<<1,v.val);
+            fprintf(stdout,"0x%0*lx",size<<1,v.val);
 }
 
 /*-----------------------------------------------------------------*/
index 59b581355bb30d9dc58a0418a0cab595726211a1..c44b40718ff2047a48350343c94c1b12f9b54f6c 100644 (file)
@@ -545,7 +545,7 @@ int simSetValue (unsigned int addr,char mem, int size, unsigned long val)
     s = buffer + strlen(buffer) -1;
     for ( i = 0 ; i < size ; i++ )
     {
-        sprintf(s," 0x%x", val & 0xff);
+        sprintf(s," 0x%lx", val & 0xff);
         s += strlen(s);
         val >>= 8;
     }
@@ -654,7 +654,7 @@ void simLoadFile (char *s)
     char buff[128];
 
     sprintf(buff,"file \"%s\"\n",s);
-    printf(buff);
+    printf("%s",buff);
     sendSim(buff);
     waitForSim(500,NULL);
 }
index 4e5165bc1fd80780b862905261a4b35cb901be51..5473d60e31c079d2bdf91fa2c52428f818d67cbf 100644 (file)
@@ -105,7 +105,7 @@ void parseFunc (char *line)
     func->modName = currModName ;
     while(*rs && *rs != ',') rs++;
     rs++;
-    sscanf(rs,"%d,%d,%d",&i,
+    sscanf(rs,"%d,%d,%hd",&i,
         &(SPEC_INTN(func->sym->etype)),
         &(SPEC_BANK(func->sym->etype)));
     SPEC_INTRTN(func->sym->etype) = i;
index c2caee07e2bab975a929088364726d80d77b6f20..b5cd2e7b9dd109f062fc7e8e34b7c41a458562a5 100644 (file)
@@ -4,7 +4,7 @@ clean:
                *.pdf *.tex *.aux *.dvi *.idx *.ilg *.out\
                *.ind *.log *.toc *~ \#* *.ps */*.css */*.pl *.gif core *.glo
        rm -rf sdcc-doc sdcc-doc.tar.bz2
-       if [ "$(srcdir)" != "." ]; then rm *.lyx; fi
+       if [ "$(srcdir)" != "." ]; then rm -f *.lyx; fi
 
 # Deleting all files created by configuring or building the program
 # -----------------------------------------------------------------
index 06d0db9f932ef742355c4b5176efbce39821b35c..53f6626ba66f7423b63c8dac750ee1cecb87ee95 100644 (file)
@@ -42,7 +42,7 @@ cl_avr::cpi_Rd_K(t_mem code)
   t_addr d;
   t_mem D, K, result, res;
 
-  d= 16+(code&0xf0)>>4;
+  d= 16+((code&0xf0)>>4);
   K= (code&0xf) | ((code&0xf00)>>8);
   D= ram->read(d);
 
@@ -92,7 +92,7 @@ cl_avr::sbci_Rd_K(t_mem code)
   t_addr d;
   t_mem D, K, result, res;
 
-  d= 16+(code&0xf0)>>4;
+  d= 16+((code&0xf0)>>4);
   K= (code&0xf) | ((code&0xf00)>>8);
   D= ram->read(d);
 
@@ -143,7 +143,7 @@ cl_avr::subi_Rd_K(t_mem code)
   t_addr d;
   t_mem D, K, result, res;
 
-  d= 16+(code&0xf0)>>4;
+  d= 16+((code&0xf0)>>4);
   K= (code&0xf) | ((code&0xf00)>>8);
   D= ram->read(d);
 
index 93738acfe60eae140e6299c19176f9568d4cf4aa..1f8399e20faeade59c04f6e6c7b370a39a1a1a4b 100644 (file)
@@ -151,9 +151,9 @@ cl_timer2::write(class cl_memory_cell *cell, t_mem *val)
           bit_t2oe)
         mode= T2MODE_CLKOUT;
     }
-  if (mode != oldmode ||
-      TR && !oldtr ||
-      !TR && oldtr)
+  if ((mode != oldmode) ||
+      (TR && !oldtr) ||
+      (!TR && oldtr))
     T_edge= t2ex_edge= 0;
 }
 
index eb648e7ff56e8cf0447cf425f2c25778b32d2d66..ba5f57c7c4f98f83ed19f00a701231c4e2505b63 100644 (file)
@@ -116,12 +116,14 @@ format_string(const char *format, ...)
 
   va_start(ap, format);
 #ifdef HAVE_VASPRINTF
+  int res;
   char *msg= NULL;
-  vasprintf(&msg, format, ap);
+  res = vasprintf(&msg, format, ap);
   return(msg);
 #elif defined HAVE_VSNPRINTF
+  int res;
   char *msg= (char*)malloc(80*25);
-  vsnprintf(msg, 80*25, format, ap);
+  res = vsnprintf(msg, 80*25, format, ap);
   return(msg);
 #elif defined HAVE__VSNPRINTF
   char *msg= (char*)malloc(80*25);
index 08d373031d284025f6f3bb03e32aae8fdab5adc3..383c40a43720ccce6623e080f5b09b6e085ddeb2 100644 (file)
@@ -212,6 +212,7 @@ tfprintf (FILE *fp, const char *szFormat, ...)
   va_list ap;
   struct dbuf_s dbuf;
   size_t len;
+  size_t res;
 
   dbuf_init (&dbuf, INITIAL_INLINEASM);
 
@@ -220,7 +221,8 @@ tfprintf (FILE *fp, const char *szFormat, ...)
   va_end (ap);
 
   len = dbuf_get_length (&dbuf);
-  fwrite(dbuf_get_buf (&dbuf), 1, len, fp);
+  res = fwrite(dbuf_get_buf (&dbuf), 1, len, fp);
+  assert(res == len);
   dbuf_destroy (&dbuf);
 }
 
index 17ab6d5d054fcb7710552d7b3ab02963ab5fcf0f..ffb95d014918e0dc7ff456c9dcb4066cbedddaeb 100644 (file)
@@ -51,364 +51,421 @@ static memRange *rangeRAM = NULL;
 
 
 /* parse a value from the configuration file */
-static int parse_config_value(char *str)
+static int
+parse_config_value (char *str)
 {
-       if (str[strlen(str) - 1] == 'K')
-               return atoi(str) * 1024;        /* like "1K" */
-               
-       else if (STRNCASECMP(str, "0x", 2) == 0)
-               return strtol(str+2, NULL, 16); /* like "0x400" */
-       
-       else
-               return atoi(str);               /* like "1024" */
+  if (str[strlen (str) - 1] == 'K')
+    return atoi (str) * 1024;        /* like "1K" */
+
+  else if (STRNCASECMP (str, "0x", 2) == 0)
+    return strtol (str+2, NULL, 16); /* like "0x400" */
+
+  else
+    return atoi (str);               /* like "1024" */
 }
 
 
 /* split a line into words */
-static int split_words(char result_word[SPLIT_WORDS_MAX][PIC14_STRING_LEN], char *str)
+static int
+split_words (char **result_word, char *str)
 {
-       char *pos = str;
-       int num_words = 0;
-       int ccount;
-       
-       while (*pos != '\0' && num_words < SPLIT_WORDS_MAX) {
-               /* remove leading spaces */
-               while (isspace(*pos) || *pos == ',')
-                       pos++;
-       
-               /* copy everything up until the first space or comma */
-               for (ccount = 0; *pos != '\0' && !isspace(*pos) && *pos != ',' && ccount < PIC14_STRING_LEN-1; ccount++, pos++)
-                       result_word[num_words][ccount] = *pos;
-               result_word[num_words][ccount] = '\0';
-               
-               num_words++;
-       }
-       
-       return num_words;
+  static const char delim[] = " \f\n\r\t\v,";
+  char *token;
+  int num_words;
+
+  /* release previously allocated words */
+  for (num_words = 0; num_words < SPLIT_WORDS_MAX; num_words++)
+    {
+      if (result_word[num_words])
+        {
+          free (result_word[num_words]);
+          result_word[num_words] = NULL;
+        } // if
+    } // for
+
+  /* split line */
+  token = strtok (str, delim);
+  num_words = 0;
+  while (token && (num_words < SPLIT_WORDS_MAX))
+    {
+      result_word[num_words] = Safe_strdup (token);
+      num_words++;
+      token = strtok (NULL, delim);
+    } // while
+
+  return num_words;
 }
 
 
 /* remove annoying prefixes from the processor name */
-static char *sanitise_processor_name(char *name)
+static char *
+sanitise_processor_name (char *name)
 {
-       char *proc_pos = name;
+  char *proc_pos = name;
 
-       if (name == NULL)
-               return NULL;
-       
-       if (STRNCASECMP(proc_pos, "pic", 3) == 0)
-               proc_pos += 3;
+  if (name == NULL)
+    return NULL;
 
-       else if (tolower(*proc_pos) == 'p')
-               proc_pos += 1;
-                               
-       return proc_pos;
+  if (STRNCASECMP (proc_pos, "pic", 3) == 0)
+    proc_pos += 3;
+
+  else if (tolower (*proc_pos) == 'p')
+    proc_pos += 1;
+
+  return proc_pos;
 }
 
 
 /* create a structure for a pic processor */
-static PIC_device *create_pic(char *pic_name, int maxram, int bankmsk, int confsiz, int program, int data, int eeprom, int io)
+static PIC_device *
+create_pic (char *pic_name, int maxram, int bankmsk, int confsiz,
+            int program, int data, int eeprom, int io)
 {
-       PIC_device *new_pic;
-       char *simple_pic_name = sanitise_processor_name(pic_name);
-       
-       new_pic = Safe_calloc(1, sizeof(PIC_device));
-       new_pic->name = Safe_calloc(strlen(simple_pic_name)+1, sizeof(char));
-       strcpy(new_pic->name, simple_pic_name);
-                       
-       new_pic->defMaxRAMaddrs = maxram;
-       new_pic->bankMask = bankmsk;
-       new_pic->hasSecondConfigReg = confsiz > 1;
-       
-       new_pic->programMemSize = program;
-       new_pic->dataMemSize = data;
-       new_pic->eepromMemSize = eeprom;
-       new_pic->ioPins = io;
+  PIC_device *new_pic;
+  char *simple_pic_name = sanitise_processor_name (pic_name);
 
-       new_pic->ram = rangeRAM;
-       
-       Pics[num_of_supported_PICS] = new_pic;
-       num_of_supported_PICS++;
-                       
-       return new_pic;
+  new_pic = Safe_calloc (1, sizeof (PIC_device));
+  new_pic->name = Safe_strdup (simple_pic_name);
+
+  new_pic->defMaxRAMaddrs = maxram;
+  new_pic->bankMask = bankmsk;
+  new_pic->hasSecondConfigReg = confsiz > 1;
+
+  new_pic->programMemSize = program;
+  new_pic->dataMemSize = data;
+  new_pic->eepromMemSize = eeprom;
+  new_pic->ioPins = io;
+
+  new_pic->ram = rangeRAM;
+
+  Pics[num_of_supported_PICS] = new_pic;
+  num_of_supported_PICS++;
+
+  return new_pic;
 }
 
 
 /* mark some registers as being duplicated across banks */
-static void register_map(int num_words, char word[SPLIT_WORDS_MAX][PIC14_STRING_LEN])
+static void
+register_map (int num_words, char **word)
 {
-       memRange *r;
-       int pcount;
-       
-       if (num_words < 3) {
-               fprintf(stderr, "WARNING: not enough values in %s regmap directive\n", DEVICE_FILE_NAME);
-               return;
-       }
+  memRange *r;
+  int pcount;
 
-       for (pcount = 2; pcount < num_words; pcount++) {
-               r = Safe_calloc(1, sizeof(memRange));
-               
-               r->start_address = parse_config_value(word[pcount]);
-               r->end_address = parse_config_value(word[pcount]);
-               r->alias = parse_config_value(word[1]);
-               r->bank = (r->start_address >> 7) & 3;
-               // add memRange to device entry for future lookup (sharebanks)
-               r->next = rangeRAM;
-               rangeRAM = r;
-       }
+  if (num_words < 3)
+    {
+      fprintf (stderr, "WARNING: not enough values in %s regmap directive\n",
+               DEVICE_FILE_NAME);
+      return;
+    } // if
+
+  for (pcount = 2; pcount < num_words; pcount++)
+    {
+      r = Safe_calloc (1, sizeof (memRange));
+
+      r->start_address = parse_config_value (word[pcount]);
+      r->end_address = parse_config_value (word[pcount]);
+      r->alias = parse_config_value (word[1]);
+      r->bank = (r->start_address >> 7) & 3;
+      // add memRange to device entry for future lookup (sharebanks)
+      r->next = rangeRAM;
+      rangeRAM = r;
+    } // for
 }
 
 
 /* define ram areas - may be duplicated across banks */
-static void ram_map(int num_words, char word[SPLIT_WORDS_MAX][PIC14_STRING_LEN])
+static void
+ram_map (int num_words, char **word)
 {
-       memRange *r;
-       
-       if (num_words < 4) {
-               fprintf(stderr, "WARNING: not enough values in %s memmap directive\n", DEVICE_FILE_NAME);
-               return;
-       }
+  memRange *r;
 
-       r = Safe_calloc(1, sizeof(memRange));
-       //fprintf (stderr, "%s: %s %s %s\n", __FUNCTION__, word[1], word[2], word[3]);
-       
-       r->start_address = parse_config_value(word[1]);
-       r->end_address = parse_config_value(word[2]);
-       r->alias = parse_config_value(word[3]);
-       r->bank = (r->start_address >> 7) & 3;
-               
-       // add memRange to device entry for future lookup (sharebanks)
-       r->next = rangeRAM;
-       rangeRAM = r;
+  if (num_words < 4)
+    {
+      fprintf (stderr, "WARNING: not enough values in %s memmap directive\n",
+               DEVICE_FILE_NAME);
+      return;
+    } // if
+
+  r = Safe_calloc (1, sizeof (memRange));
+  //fprintf (stderr, "%s: %s %s %s\n", __FUNCTION__, word[1], word[2], word[3]);
+
+  r->start_address = parse_config_value (word[1]);
+  r->end_address = parse_config_value (word[2]);
+  r->alias = parse_config_value (word[3]);
+  r->bank = (r->start_address >> 7) & 3;
+
+  // add memRange to device entry for future lookup (sharebanks)
+  r->next = rangeRAM;
+  rangeRAM = r;
 }
 
-static void setMaxRAM(int size)
+static void
+setMaxRAM (int size)
 {
-       maxRAMaddress = size;
+  maxRAMaddress = size;
 
-       if (maxRAMaddress < 0) {
-               fprintf(stderr, "invalid maxram 0x%x setting in %s\n",
-                       maxRAMaddress, DEVICE_FILE_NAME);
-               return;
-       }
+  if (maxRAMaddress < 0)
+    {
+      fprintf (stderr, "invalid maxram 0x%x setting in %s\n",
+               maxRAMaddress, DEVICE_FILE_NAME);
+      return;
+    } // if
 }
 
 /* read the file with all the pic14 definitions and pick out the definition
  * for a processor if specified. if pic_name is NULL reads everything */
-static PIC_device *find_device(char *pic_name)
+static PIC_device *
+find_device (char *pic_name)
 {
-       FILE *pic_file;
-       char pic_buf[PIC14_STRING_LEN];
-       char *pic_buf_pos;
-       int found_processor = FALSE;
-       int done = FALSE;
-       char processor_name[SPLIT_WORDS_MAX][PIC14_STRING_LEN];
-       int num_processor_names = 0;
-       int pic_maxram = 0;
-       int pic_bankmsk = 0;
-       int pic_confsiz = 0;
-       int pic_program = 0;
-       int pic_data = 0;
-       int pic_eeprom = 0;
-       int pic_io = 0;
-       char *simple_pic_name;
-       char *dir;
-       char filename[512];
-       int len = 512;
-       
-       /* allow abbreviations of the form "f877" - convert to "16f877" */
-       simple_pic_name = sanitise_processor_name(pic_name);
-       num_of_supported_PICS = 0;
-       
-       /* open the piclist file */
-       /* first scan all include directories */
-       pic_file = NULL;
-       //fprintf( stderr, "%s: searching %s\n", __FUNCTION__, DEVICE_FILE_NAME );
-       for (dir = setFirstItem(userIncDirsSet);
-               !pic_file && dir;
-               dir = setNextItem(userIncDirsSet))
-       {
-         //fprintf( stderr, "searching1 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s", dir,
-           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
-         pic_file = fopen( filename, "rt" );
-         if (pic_file) break;
-       } // for
-
-       for (dir = setFirstItem(includeDirsSet);
-               !pic_file && dir;
-               dir = setNextItem(includeDirsSet))
-       {
-         //fprintf( stderr, "searching2 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s", dir,
-           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
-         pic_file = fopen( filename, "rt" );
-         if (pic_file) break;
-       } // for
-
-       for (dir = setFirstItem(libDirsSet);
-               !pic_file && dir;
-               dir = setNextItem(libDirsSet))
-       {
-         //fprintf( stderr, "searching3 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s", dir,
-           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
-         pic_file = fopen( filename, "rt" );
-         if (pic_file) break;
-       } // for
-
-       for (dir = setFirstItem(libPathsSet);
-               !pic_file && dir;
-               dir = setNextItem(libPathsSet))
-       {
-         //fprintf( stderr, "searching4 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s", dir,
-           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
-         pic_file = fopen( filename, "rt" );
-         if (pic_file) break;
-       } // for
-
-       if (!pic_file) {
-         SNPRINTF(&filename[0], len, "%s",
-           DATADIR LIB_DIR_SUFFIX
-           DIR_SEPARATOR_STRING "pic"
-           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
-         pic_file = fopen( filename, "rt" );
-       } // if
-
-        if (pic_file == NULL) {
-            fprintf(stderr, "can't find %s\n", DEVICE_FILE_NAME);
-            return NULL;
+  FILE *pic_file;
+  char pic_buf[PIC14_STRING_LEN];
+  int found_processor = FALSE;
+  int done = FALSE;
+  char **processor_name;
+  int num_processor_names = 0;
+  int pic_maxram = 0;
+  int pic_bankmsk = 0;
+  int pic_confsiz = 0;
+  int pic_program = 0;
+  int pic_data = 0;
+  int pic_eeprom = 0;
+  int pic_io = 0;
+  char *simple_pic_name;
+  char *dir;
+  char filename[512];
+  int len = 512;
+  char **pic_word;
+  int num_pic_words;
+  int wcount;
+
+  pic_word = Safe_calloc (sizeof (char *), SPLIT_WORDS_MAX);
+  processor_name = Safe_calloc (sizeof (char *), SPLIT_WORDS_MAX);
+
+  /* allow abbreviations of the form "f877" - convert to "16f877" */
+  simple_pic_name = sanitise_processor_name (pic_name);
+  num_of_supported_PICS = 0;
+
+  /* open the piclist file */
+  /* first scan all include directories */
+  pic_file = NULL;
+  //fprintf (stderr, "%s: searching %s\n", __FUNCTION__, DEVICE_FILE_NAME);
+  for (dir = setFirstItem (userIncDirsSet);
+      !pic_file && dir;
+      dir = setNextItem (userIncDirsSet))
+    {
+      //fprintf (stderr, "searching1 %s\n", dir);
+      SNPRINTF (&filename[0], len, "%s%s", dir,
+                DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
+      pic_file = fopen (filename, "rt");
+      if (pic_file) break;
+    } // for
+
+  for (dir = setFirstItem (includeDirsSet);
+      !pic_file && dir;
+      dir = setNextItem (includeDirsSet))
+    {
+      //fprintf (stderr, "searching2 %s\n", dir);
+      SNPRINTF (&filename[0], len, "%s%s", dir,
+                DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
+      pic_file = fopen (filename, "rt");
+      if (pic_file) break;
+    } // for
+
+  for (dir = setFirstItem (libDirsSet);
+      !pic_file && dir;
+      dir = setNextItem (libDirsSet))
+    {
+      //fprintf (stderr, "searching3 %s\n", dir);
+      SNPRINTF (&filename[0], len, "%s%s", dir,
+                DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
+      pic_file = fopen (filename, "rt");
+      if (pic_file) break;
+    } // for
+
+  for (dir = setFirstItem (libPathsSet);
+      !pic_file && dir;
+      dir = setNextItem (libPathsSet))
+    {
+      //fprintf (stderr, "searching4 %s\n", dir);
+      SNPRINTF (&filename[0], len, "%s%s", dir,
+                DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
+      pic_file = fopen (filename, "rt");
+      if (pic_file) break;
+    } // for
+
+  if (!pic_file)
+    {
+      SNPRINTF (&filename[0], len, "%s",
+                DATADIR LIB_DIR_SUFFIX
+                DIR_SEPARATOR_STRING "pic"
+                DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
+      pic_file = fopen (filename, "rt");
+    } // if
+
+  if (pic_file == NULL)
+    {
+      fprintf (stderr, "can't find %s\n", DEVICE_FILE_NAME);
+      return NULL;
+    } // if
+
+  if (options.verbose)
+    printf ("Using devices from %s.\n", filename);
+
+  /* read line by line */
+  pic_buf[sizeof (pic_buf)-1] = '\0';
+  while (fgets (pic_buf, sizeof (pic_buf)-1, pic_file) != NULL && !done)
+    {
+      /* strip comments */
+      {
+        char *comment = strchr (pic_buf, '#');
+        if (comment)
+          *comment = 0;
+      }
+
+      /* split into fields */
+      num_pic_words = split_words (pic_word, pic_buf);
+
+      /* ignore comment / empty lines */
+      if (num_pic_words > 0)
+        {
+
+          if (STRCASECMP (pic_word[0], "processor") == 0)
+            {
+              if (pic_name == NULL)
+                {
+                  int dcount;
+
+                  /* this is the mode where we read all the processors in - store the names for now */
+                  if (num_processor_names > 0)
+                    {
+                      /* store away all the previous processor definitions */
+                      for (dcount = 1; dcount < num_processor_names; dcount++)
+                        {
+                          create_pic (processor_name[dcount], pic_maxram,
+                                      pic_bankmsk, pic_confsiz, pic_program,
+                                      pic_data, pic_eeprom, pic_io);
+                        } // for
+                    } // if
+
+                  /* copy processor names */
+                  num_processor_names = num_pic_words;
+                  for (dcount = 1; dcount < num_processor_names; dcount++)
+                    {
+                      processor_name[dcount] = pic_word[dcount];
+                      pic_word[dcount] = NULL;
+                    } // for
+                } // if
+              else
+                {
+                  /* if we've just completed reading a processor definition stop now */
+                  if (found_processor)
+                    done = TRUE;
+                  else
+                    {
+                      /* check if this processor name is a match */
+                      for (wcount = 1; wcount < num_pic_words; wcount++)
+                        {
+                          /* skip uninteresting prefixes */
+                          char *found_name = sanitise_processor_name (pic_word[wcount]);
+
+                          if (STRCASECMP (found_name, simple_pic_name) == 0)
+                            found_processor = TRUE;
+                        } // for
+                    } // if
+                } // if
+            } // if
+          else
+            {
+              if (found_processor || pic_name == NULL)
+                {
+                  /* only parse a processor section if we've found the one we want */
+                  if (STRCASECMP (pic_word[0], "maxram") == 0 && num_pic_words > 1)
+                    {
+                      pic_maxram = parse_config_value (pic_word[1]);
+                      setMaxRAM (pic_maxram);
+                    } // if
+
+                  else if (STRCASECMP (pic_word[0], "bankmsk") == 0 && num_pic_words > 1)
+                    pic_bankmsk = parse_config_value (pic_word[1]);
+
+                  else if (STRCASECMP (pic_word[0], "confsiz") == 0 && num_pic_words > 1)
+                    pic_confsiz = parse_config_value (pic_word[1]);
+
+                  else if (STRCASECMP (pic_word[0], "program") == 0 && num_pic_words > 1)
+                    pic_program = parse_config_value (pic_word[1]);
+
+                  else if (STRCASECMP (pic_word[0], "data") == 0 && num_pic_words > 1)
+                    pic_data = parse_config_value (pic_word[1]);
+
+                  else if (STRCASECMP (pic_word[0], "eeprom") == 0 && num_pic_words > 1)
+                    pic_eeprom = parse_config_value (pic_word[1]);
+
+                  else if (STRCASECMP (pic_word[0], "io") == 0 && num_pic_words > 1)
+                    pic_io = parse_config_value (pic_word[1]);
+
+                  else if (STRCASECMP (pic_word[0], "regmap") == 0 && num_pic_words > 2)
+                    {
+                      if (found_processor)
+                        register_map (num_pic_words, pic_word);
+                    } // if
+
+                  else if (STRCASECMP (pic_word[0], "memmap") == 0 && num_pic_words > 2)
+                    {
+                      if (found_processor)
+                        ram_map (num_pic_words, pic_word);
+                    } // if
+
+                  else
+                    {
+                      fprintf (stderr, "WARNING: %s: bad syntax `%s'\n",
+                               DEVICE_FILE_NAME, pic_word[0]);
+                    } // if
+                } // if
+            } // if
         } // if
+    } // while
 
-       if (options.verbose) {
-           printf ("Using devices from %s.\n", filename);
-       } // if
-       
-       /* read line by line */
-       pic_buf[sizeof(pic_buf)-1] = '\0';
-       while (fgets(pic_buf, sizeof(pic_buf)-1, pic_file) != NULL && !done) {
-               unsigned llen;
-               llen = strlen (pic_buf);
-               
-               /* remove trailing spaces */
-               while (llen && isspace(pic_buf[llen-1])) {
-                       pic_buf[llen-1] = '\0';
-                       llen--;
-               }
-               
-               /* remove leading spaces */
-               for (pic_buf_pos = pic_buf; isspace(*pic_buf_pos); pic_buf_pos++)
-               {}
-               
-               /* ignore comment / empty lines */
-               if (*pic_buf_pos != '\0' && *pic_buf_pos != '#') {
-                       
-                       /* split into fields */
-                       char pic_word[SPLIT_WORDS_MAX][PIC14_STRING_LEN];
-                       int num_pic_words;
-                       int wcount;
-                       
-                       num_pic_words = split_words(pic_word, pic_buf_pos);
-                       
-                       if (STRCASECMP(pic_word[0], "processor") == 0) {
-                       
-                               if (pic_name == NULL) {
-                                       /* this is the mode where we read all the processors in - store the names for now */
-                                       if (num_processor_names > 0) {
-                                               /* store away all the previous processor definitions */
-                                               int dcount;
-                                               
-                                               for (dcount = 1; dcount < num_processor_names; dcount++)
-                                                       create_pic(processor_name[dcount], pic_maxram, pic_bankmsk,
-                                                                  pic_confsiz, pic_program, pic_data, pic_eeprom, pic_io);
-                                       }
-                                       
-                                       num_processor_names = split_words(processor_name, pic_buf_pos);
-                               }
-                               else {
-                                       /* if we've just completed reading a processor definition stop now */
-                                       if (found_processor)
-                                               done = TRUE;
-                                       else {
-                                               /* check if this processor name is a match */
-                                               for (wcount = 1; wcount < num_pic_words; wcount++) {
-                                                       
-                                                       /* skip uninteresting prefixes */
-                                                       char *found_name = sanitise_processor_name(pic_word[wcount]);
-
-                                                       if (STRCASECMP(found_name, simple_pic_name) == 0)
-                                                               found_processor = TRUE;
-                                               }
-                                       }
-                               }
-                       }
-                       
-                       else {
-                               if (found_processor || pic_name == NULL) {
-                                       /* only parse a processor section if we've found the one we want */
-                                       if (STRCASECMP(pic_word[0], "maxram") == 0 && num_pic_words > 1) {
-                                               pic_maxram = parse_config_value(pic_word[1]);
-                                               setMaxRAM(pic_maxram);
-                                       }
-                                       else if (STRCASECMP(pic_word[0], "bankmsk") == 0 && num_pic_words > 1)
-                                               pic_bankmsk = parse_config_value(pic_word[1]);
-                       
-                                       else if (STRCASECMP(pic_word[0], "confsiz") == 0 && num_pic_words > 1)
-                                               pic_confsiz = parse_config_value(pic_word[1]);
-                       
-                                       else if (STRCASECMP(pic_word[0], "program") == 0 && num_pic_words > 1)
-                                               pic_program = parse_config_value(pic_word[1]);
-                       
-                                       else if (STRCASECMP(pic_word[0], "data") == 0 && num_pic_words > 1)
-                                               pic_data = parse_config_value(pic_word[1]);
-                       
-                                       else if (STRCASECMP(pic_word[0], "eeprom") == 0 && num_pic_words > 1)
-                                               pic_eeprom = parse_config_value(pic_word[1]);
-                       
-                                       else if (STRCASECMP(pic_word[0], "io") == 0 && num_pic_words > 1)
-                                               pic_io = parse_config_value(pic_word[1]);
-                       
-                                       else if (STRCASECMP(pic_word[0], "regmap") == 0 && num_pic_words > 2) {
-                                               if (found_processor)
-                                                       register_map(num_pic_words, pic_word);
-                                       }
-                                       else if (STRCASECMP(pic_word[0], "memmap") == 0 && num_pic_words > 2) {
-                                               if (found_processor)
-                                                       ram_map(num_pic_words, pic_word);
-                                       }
-                                       else {
-                                               fprintf(stderr, "WARNING: %s: bad syntax `%s'\n", DEVICE_FILE_NAME, pic_word[0]);
-                                       }
-                               }
-                       }
-               }
-       }
-       
-       fclose(pic_file);
-
-       /* if we're in read-the-lot mode then create the final processor definition */
-       if (pic_name == NULL) {
-           
-               if (num_processor_names > 0) {
-                       /* store away all the previous processor definitions */
-                       int dcount;
-               
-                       for (dcount = 1; dcount < num_processor_names; dcount++)
-                               create_pic(processor_name[dcount], pic_maxram, pic_bankmsk,
-                                          pic_confsiz, pic_program, pic_data, pic_eeprom, pic_io);
-               }
-       }
-       else {
-               /* in search mode */
-               if (found_processor) {
-                       /* create a new pic entry */
-                       return create_pic(pic_name, pic_maxram, pic_bankmsk,
-                                         pic_confsiz, pic_program, pic_data, pic_eeprom, pic_io);
-               }
-       }
-       
-       return NULL;
+  fclose (pic_file);
+
+  split_words (pic_word, NULL);
+  free (pic_word);
+
+  /* if we're in read-the-lot mode then create the final processor definition */
+  if (pic_name == NULL)
+    {
+      if (num_processor_names > 0)
+        {
+          /* store away all the previous processor definitions */
+          int dcount;
+
+          for (dcount = 1; dcount < num_processor_names; dcount++)
+            {
+              create_pic (processor_name[dcount], pic_maxram, pic_bankmsk,
+                          pic_confsiz, pic_program, pic_data, pic_eeprom,
+                          pic_io);
+            } // for
+        } // if
+    } // if
+  else
+    {
+      /* in search mode */
+      if (found_processor)
+        {
+          split_words (processor_name, NULL);
+          free (processor_name);
+
+          /* create a new pic entry */
+          return create_pic (pic_name, pic_maxram, pic_bankmsk,
+                             pic_confsiz, pic_program, pic_data,
+                             pic_eeprom, pic_io);
+        } // if
+    } // if
+
+  split_words (processor_name, NULL);
+  free (processor_name);
+
+  return NULL;
 }
 
 /*-----------------------------------------------------------------*
@@ -421,7 +478,8 @@ static PIC_device *find_device(char *pic_name)
  * list_alias - if non-zero, print all of the supported aliases
  *              for a device (e.g. F84, 16F84, etc...)
  *-----------------------------------------------------------------*/
-static void list_valid_pics(int ncols)
+static void
+list_valid_pics(int ncols)
 {
        int col=0,longest;
        int i,k,l;
index c2de470d204037295bb23b36c5ed88228bf92ea0..61e125e46aa5364ab98971baa511c0e82ef5f219 100644 (file)
@@ -282,7 +282,10 @@ dbuf_chomp (struct dbuf_s *dbuf)
 void
 dbuf_write (struct dbuf_s *dbuf, FILE *dest)
 {
-  fwrite (dbuf_get_buf (dbuf), 1, dbuf_get_length (dbuf), dest);
+  size_t res;
+  size_t len = dbuf_get_length (dbuf);
+  res = fwrite (dbuf_get_buf (dbuf), 1, len, dest);
+  assert(res == len);
 }
 
 
index 908558354adc9ee699ce8062800c945b5dc8d922..812c91adefe4bfa314312f0014a774456a1b4f11 100644 (file)
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#include <assert.h>
 #include "config.h"
 #include "system.h"
 #include "cpplib.h"
@@ -193,9 +194,11 @@ scan_translation_unit_trad (cpp_reader *pfile)
 {
   while (_cpp_read_logical_line_trad (pfile))
     {
+      size_t res;
       size_t len = pfile->out.cur - pfile->out.base;
       maybe_print_line (pfile->out.first_line);
-      fwrite (pfile->out.base, 1, len, print.outf);
+      res = fwrite (pfile->out.base, 1, len, print.outf);
+      assert(res == len);
       print.printed = 1;
       if (!CPP_OPTION (pfile, discard_comments))
        account_for_newlines (pfile->out.base, len);
index ab04177ea05734ba958e087f98e1f5b5c7ef509f..7c7c03a2cc022724a7d99ded7e31c41b3a598788 100644 (file)
@@ -1782,6 +1782,8 @@ cpp_type2name (enum cpp_ttype type)
 void
 cpp_output_token (const cpp_token *token, FILE *fp)
 {
+  size_t res;
+
   switch (TOKEN_SPELL (token))
     {
     case SPELL_OPERATOR:
@@ -1815,7 +1817,8 @@ cpp_output_token (const cpp_token *token, FILE *fp)
             {
               unsigned char buffer[10];
               i += utf8_to_ucn (buffer, name + i) - 1;
-              fwrite (buffer, 1, 10, fp);
+              res = fwrite (buffer, 1, 10, fp);
+              assert (10 == res);
             }
           else
             fputc (NODE_NAME (token->val.node)[i], fp);
@@ -1823,7 +1826,8 @@ cpp_output_token (const cpp_token *token, FILE *fp)
       break;
 
     case SPELL_LITERAL:
-      fwrite (token->val.str.text, 1, token->val.str.len, fp);
+      res = fwrite (token->val.str.text, 1, token->val.str.len, fp);
+      assert (token->val.str.len == res);
       break;
 
     case SPELL_NONE:
index 764d5e3afd9bab3d66441c733d5c17f05016ee47..26e5f03a7b27a6fee5c5d38bb202e940105878fd 100644 (file)
@@ -1657,7 +1657,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
              function-like macros, but not at the end.  */
           if (following_paste_op)
             {
-              cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
+              cpp_error (pfile, CPP_DL_ERROR, "%s", paste_op_error_msg);
               return false;
             }
           break;
@@ -1670,7 +1670,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
              function-like macros, but not at the beginning.  */
           if (macro->count == 1)
             {
-              cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
+              cpp_error (pfile, CPP_DL_ERROR, "%s", paste_op_error_msg);
               return false;
             }
 
index e8a36d611c53e2b7789b0d712f3be51df1bc7d8a..9367f8f32b462ad06ac9070a6626cee3bdb55873 100644 (file)
@@ -48,6 +48,24 @@ int NumRelFiles=0;
 #define EQ(A,B) !strcmp((A),(B))
 #define NEQ(A,B) strcmp((A),(B))
 
+#if 1
+#include <assert.h>
+#define __assert(COND)  do { assert(COND); } while (0)
+#else
+#define __assert(COND)  do { (void)(COND); } while (0)
+#endif
+
+#define fgets(S, SIZE, STREAM)  do {                    \
+  char *__s4567 = S;                                    \
+  char *__res4567 = fgets(__s4567, SIZE, STREAM);       \
+  __assert(__s4567 == __res4567);                       \
+} while (0)
+
+#define system(CMD)             do {                    \
+  int __res4568 = system(CMD);                          \
+  __assert(-1 != __res4568);                            \
+} while (0)
+
 int action=OPT_NONE;
 FILE *lib, *newlib, *rel, *adb, *libindex;
 char FLine[MAXLINE+1];
index 83d4ec6990991627f4fd0a36cbfd6f1a230e881d..b6acaf4c872dde008a089962a2be76a78aa29499 100644 (file)
@@ -1,5 +1,6 @@
 /** @name makebin - turn a .ihx file into a binary image.
  */
+#include <assert.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -48,6 +49,7 @@ int main(int argc, char **argv)
 {
     int size = 32768, pack = 0, real_size = 0;
     BYTE *rom;
+    size_t res;
     char line[256];
     char *p;
 
@@ -112,10 +114,13 @@ int main(int argc, char **argv)
            real_size = addr;
     }
 
-    if (pack)
-        fwrite(rom, 1, real_size, stdout);
-    else
-        fwrite(rom, 1, size, stdout);
+    if (pack) {
+        res = fwrite(rom, 1, real_size, stdout);
+        assert(res == real_size);
+    } else {
+        res = fwrite(rom, 1, size, stdout);
+        assert(res == size);
+    }
     
     return 0;
 }