home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 240.lha / PickPacket_v1.0 / Sources / help.c < prev    next >
C/C++ Source or Header  |  1989-05-04  |  3KB  |  95 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989 The Software Distillery.                    *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by John Toebes and Doug Walker               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           235 Trillingham Lane                                 *
  7. * ======             Cary, NC 27513                                       *
  8. *                    BBS:(919)-471-6436                                   *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <graphics/gfxmacros.h>
  13. #include <graphics/rastport.h>
  14. #include <libraries/dos.h>
  15. #include <proto/intuition.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/graphics.h>
  19. #include <string.h>
  20.  
  21. #include "pickpack.h"
  22. #include "struct.h"
  23.  
  24. /* Macro to declare automatic pointer to longword-aligned area */
  25. #define STALIGN(name,type) char c_##name[sizeof(type)+3]; \
  26.                            type * name = (type *)(((long)(c_##name + 3)>>2)<<2)
  27.  
  28. int GetHelp(data, len)
  29. char **data;
  30. int *len;
  31. {
  32.    struct VIEWDATA *vd;
  33.    int rc;
  34.    BPTR fp, lock;
  35.    STALIGN(fib, struct FileInfoBlock);
  36.  
  37.    BUG(1, ("GetHelp: Entry\n"))
  38.  
  39.    if(!(lock=Lock(HELPFILE, ACCESS_READ)) ||
  40.       !Examine(lock, fib) )
  41.    {
  42.       BUG(2, ("GetHelp: Can't %s file '%s'", 
  43.          lock ? "Lock" : "Examine", HELPFILE))
  44.       if(lock) UnLock(lock);
  45.       status("Can't find help file '" HELPFILE "'");
  46.       BUG(1, ("GetHelp: Exit, returning 1\n"))
  47.       return(1);
  48.    }
  49.  
  50.    *len = fib->fib_Size+sizeof(struct VIEWDATA);
  51.    UnLock(lock);
  52.  
  53.    fp = NULL;
  54.    rc = 0;
  55.    if(!(vd = (struct ViewData *)AllocMem(*len, 0)) ||
  56.       !(fp=Open(HELPFILE, MODE_OLDFILE)) ||
  57.       Read(fp, vd->buf, (long)*len) <= 0)
  58.    {
  59.       BUG(2, ("GetHelp: Can't read file '%s'\n", HELPFILE))
  60.       status("Can't find help file '" HELPFILE "'");
  61.       if(*data) FreeMem(*data, *len);
  62.       *data = NULL;
  63.       rc = 2;
  64.    }
  65.    else
  66.       *data = (char *)vd;
  67.    if(fp) Close(fp);
  68.  
  69.    BUG(1, ("GetHelp: Exit, returning %d\n", rc))
  70.  
  71.    return(rc);
  72. }
  73.  
  74.  
  75. int CountLines(data, len)
  76. char *data;
  77. int len;
  78. {
  79.    int i, lines;
  80.    char *pos;
  81.  
  82.    for(i=lines=0, pos=data; i<len; i++, pos++)
  83.    {
  84.       if(*pos == '\n')
  85.       {
  86.          lines++;
  87.          *pos = '\0';
  88.       }
  89.    }
  90.    /* Now at end of buffer - add an extra zero */
  91.    *pos = '\0';
  92.  
  93.    return(lines);
  94. }
  95.