home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / nonvolatile / WipeNV.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  2.6 KB  |  107 lines

  1. /* WipeNV.c
  2.  * 
  3.  * Delete everything in NV-RAM.
  4.  * 
  5.  * 
  6.  */
  7.  
  8. /* Includes --------------------------------------------- */
  9. #include <exec/types.h>
  10. #include <exec/libraries.h>
  11. #include <exec/memory.h>
  12. #include <dos/dos.h>
  13. #include <libraries/nonvolatile.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <clib/nonvolatile_protos.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #include <pragmas/nonvolatile_pragmas.h>
  21.  
  22. /* Defines ------------------------------------------ */
  23. #define PROGNAME "WipeNV"
  24. #define ERRMSG_LIBNOOPEN "Couldn't open %s V%ld (or better)!\n"
  25. #define APPNAMESIZE 80
  26.  
  27. /* Protos ------------------------------------------ */
  28. static VOID GoodBye(int);
  29. static LONG doInit(VOID);
  30.  
  31. /* Globals --------------------------------------- */
  32. struct Library *NVBase;
  33. int rc;
  34.  
  35. VOID main(int argc, UBYTE *argv[]) {
  36.     struct MinList *ml;
  37.     struct MinNode *mn;
  38.     struct NVEntry *nve;
  39.     UBYTE appName[APPNAMESIZE];
  40.  
  41.     if (!doInit()) {
  42.         GoodBye(RETURN_FAIL);
  43.     }
  44.  
  45.     rc = RETURN_OK;
  46.  
  47.     if (ml = GetNVList(NULL,FALSE)) {
  48.         mn = ml->mlh_Head;
  49.         while (mn) {
  50.             if (mn->mln_Succ) {
  51.                 nve = (struct NVEntry *)mn;
  52.                 if (!(nve->nve_Size)) {
  53.                     /* tis name to be copied for use in deletion */
  54.                     stccpy(appName, nve->nve_Name, APPNAMESIZE);
  55.                 }
  56.                 else {
  57.                     if (nve->nve_Protection) {
  58.                         SetNVProtection(appName, nve->nve_Name, 0, FALSE);
  59.                     }
  60.                     Printf("Deleting %s %s ...", appName, nve->nve_Name);
  61.                     if (DeleteNV(appName, nve->nve_Name, FALSE)) {
  62.                         PutStr("done.\n");
  63.                     }
  64.                     else {
  65.                         PutStr("error!\n");
  66.                         rc = RETURN_ERROR;
  67.                     }
  68.                 }
  69.             }
  70.             mn = mn->mln_Succ;
  71.             if (CheckSignal(SIGBREAKF_CTRL_C)) {
  72.                 FreeNVData(ml);
  73.                 GoodBye(rc);
  74.             }
  75.         }
  76.         FreeNVData(ml);
  77.     }
  78.  
  79.     GoodBye(rc);
  80. }
  81.  
  82. /* GoodBye ===============================================
  83.    Clean-exit routine.
  84.  */
  85. static VOID GoodBye(int rc) {
  86.     if (NVBase) {
  87.         CloseLibrary(NVBase);
  88.     }
  89.  
  90.     exit(rc);
  91. }
  92.  
  93. /* doInit =============================================
  94.  * Open libraries, call ReadArgs() if necessary.
  95.  * Returns TRUE for success, FALSE otherwise.
  96.  */
  97. static LONG doInit(VOID) {
  98.     NVBase = OpenLibrary("nonvolatile.library", 39L);
  99.     if (!NVBase) {
  100.         Printf(ERRMSG_LIBNOOPEN, "nonvolatile.library", 39L);
  101.         return(FALSE);
  102.     }
  103.  
  104.     return(TRUE);
  105. }
  106.  
  107.