home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / os20 / util / stickit / source / files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  2.8 KB  |  143 lines

  1. /***************************************
  2.  *************   files.c   *************
  3.  ***************************************/
  4.  
  5. #include <exec/types.h>
  6. #include <exec/libraries.h>
  7. #include <intuition/intuition.h>
  8. #include <graphics/text.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/dos_protos.h>
  12. #include <clib/intuition_protos.h>
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include "consts.h"
  19. #include "structs.h"
  20. #include "prototype.h"
  21.  
  22. extern struct Window *editWnd;
  23.  
  24. extern prjptr prj;
  25.  
  26. void readnotefile()
  27.    {
  28.    struct ndnode *ndptr;
  29.    nteptr newnote;
  30.    
  31.    FILE *ntefp;
  32.  
  33.    char error_msg[STRLEN_ERRORMSG];
  34.    char strpos[STRLEN_INLINE];
  35.    char strtitle[STRLEN_INLINE];
  36.    char strnote[STRLEN_INLINE];
  37.  
  38.    int l;
  39.  
  40.    ntefp = fopen(prj->notefile,"r");
  41.  
  42.    if (!ntefp)
  43.       {
  44.       sprintf(error_msg,"Could not open notefile \"%s\"",
  45.          prj->notefile);
  46.       error(error_msg,ERR_FOPEN);
  47.       }
  48.  
  49.    /***   Give sleep pointer if edit window open   ***/
  50.  
  51.    if (editWnd)
  52.       andyssleeppointer(editWnd);
  53.  
  54.    prj->no_notes = 0;
  55.  
  56.    while ((fgets(strpos,STRLEN_INLINE,ntefp)) &&
  57.          (fgets(strtitle,STRLEN_INLINE,ntefp)) &&
  58.          (fgets(strnote,STRLEN_INLINE,ntefp)))
  59.       {
  60.       /***   Strip \n from strings   ***/
  61.  
  62.       for (l = 0; l < STRLEN_INLINE; l++)
  63.          {
  64.          strtitle[l] = (strtitle[l] == '\n')?'\0':strtitle[l];
  65.          strnote[l] = (strnote[l] == '\n')?'\0':strnote[l];
  66.          }
  67.  
  68.       /*** Create a new note in the linked list   ***/
  69.  
  70.       ndptr = llealloc();
  71.       newnote = notealloc();
  72.       ndptr->data = newnote;
  73.  
  74.       if (!newnote)
  75.          {
  76.          fclose(ntefp);
  77.          error("Can't allocate new note",ERR_MALLOC);
  78.          }
  79.  
  80.       if ((sscanf(strpos,"%d,%d",&newnote->xpos,&newnote->ypos) != 2))
  81.          {
  82.          error("Error in notefile date",ERR_NOTEFILE);
  83.          continue;
  84.          }
  85.  
  86.       strncpy(newnote->title,strtitle,STRLEN_TITLE);
  87.       strncpy(newnote->note,strnote,STRLEN_NOTE);
  88.  
  89.       newnote->show = TRUE;
  90.  
  91.       lleadd(prj->notes_end->prev,ndptr);
  92.  
  93.       prj->no_notes++;
  94.  
  95.       /***   Make last note current   ***/
  96.  
  97.       prj->currnode = ndptr;
  98.       }
  99.  
  100.    fclose(ntefp);
  101.  
  102.    prj->filechanged = FALSE;
  103.  
  104.    if (editWnd)
  105.       ClearPointer(editWnd);
  106.    }
  107.  
  108. void writenotefile()
  109.    {
  110.    struct ndnode *ndptr;
  111.    nteptr currnote;
  112.  
  113.    FILE *outfp;
  114.  
  115.    outfp = fopen(prj->notefile,"w");
  116.        
  117.    if (!outfp)
  118.       {
  119.       error("Could not save to note file",ERR_FILESAVE);
  120.       return;
  121.       }
  122.  
  123.    andyssleeppointer(editWnd);
  124.  
  125.    ndptr = prj->notes_start->next;
  126.  
  127.    while (ndptr->next)
  128.       {
  129.       currnote = ndptr->data;
  130.  
  131.       fprintf(outfp,"%d,%d\n",currnote->xpos,currnote->ypos);
  132.       fprintf(outfp,"%s\n%s\n",currnote->title,currnote->note);
  133.  
  134.       ndptr = ndptr->next;
  135.       }
  136.  
  137.    fclose(outfp);
  138.  
  139.    prj->filechanged = FALSE;
  140.  
  141.    ClearPointer(editWnd);
  142.    }
  143.