home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / GETFILE.C < prev    next >
Text File  |  1996-04-18  |  5KB  |  118 lines

  1. /*****************************************************************************/
  2. /* File:                                                                     */
  3. /*   getfile.c                                                               */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  Get the file specified by the user                                       */
  8. /*                                                                           */
  9. /*                                                                           */
  10. /* History:                                                                  */
  11. /*                                                                           */
  12. /*   02/29/96 Revides.                                                       */
  13. /*                                                                           */
  14. /*****************************************************************************/
  15.  
  16. #include "all.h"
  17.  
  18. extern AFILE*   allfps;
  19. extern UINT     LinesPer;
  20.  
  21. /*****************************************************************************/
  22. /* GetFile                                                                   */
  23. /*                                                                           */
  24. /* Description:                                                              */
  25. /*                                                                           */
  26. /*   Build a view for the file specified by the user.                        */
  27. /*                                                                           */
  28. /* Parameters:                                                               */
  29. /*                                                                           */
  30. /*   fname    pointer to filename string                                     */
  31. /*                                                                           */
  32. /* Return:                                                                   */
  33. /*                                                                           */
  34. /*   cur_afp  pointer to AFILE struct for the file                           */
  35. /*   NULL     file not found                                                 */
  36. /*                                                                           */
  37. /* Assumptions:                                                              */
  38. /*                                                                           */
  39. /*   1. The AFILE structure for EXE file always exists (i.e. allfps <> NULL) */
  40. /*                                                                           */
  41. /*****************************************************************************/
  42. AFILE *GetFile(UCHAR *fname)
  43. {
  44.  AFILE *cur_afp;
  45.  AFILE *fp;
  46.  AFILE *plast;
  47.  uchar *fn;
  48.  uchar *afn;
  49.  uchar *apn;
  50.  
  51.  uint PathInfoFlag;
  52.  
  53.  
  54.  PathInfoFlag = FALSE;
  55.  
  56.  
  57.  if( strchr(fname,0x5C) )
  58.     PathInfoFlag = TRUE;
  59.  
  60.  fn = strrchr(fname, '\\');
  61.  fn = (fn) ? (fn + 1) : fname ;
  62.  
  63. /*****************************************************************************/
  64. /* Search the list of AFILE structures to find the file name in it.          */
  65. /* If found then return pointer to the AFILE struct.                         */
  66. /* If not then search MODULE list of each DEBFILE struct  to locate          */
  67. /* lineno info area and then filename within it and try to match user's fname*/
  68. /* with lineno info filename.                                                */
  69. /*****************************************************************************/
  70.  cur_afp = allfps;
  71.  while (cur_afp != NULL)
  72.  {
  73.     apn = (cur_afp->filename);
  74.     afn = strrchr(apn, '\\');
  75.     afn = (afn) ? (afn + 1) : apn;
  76.     if (PathInfoFlag == TRUE)
  77.     {
  78.       if (stricmp(fname,apn+1) == 0)
  79.          break;
  80.     }
  81.     else
  82.     {
  83.       if (stricmp(fn,afn) == 0)
  84.          break;
  85.     }
  86.     cur_afp = cur_afp->next;
  87.  }
  88.  
  89. /*****************************************************************************/
  90. /* User's filename not found in the AFILE list so search MODULE list for     */
  91. /* each executable file (exe + dll)                                          */
  92. /*****************************************************************************/
  93.  if(cur_afp == NULL)
  94.  {
  95.   /***************************************************************************/
  96.   /* - build a view and add it to the ring of views.                         */
  97.   /***************************************************************************/
  98.   for( plast=(AFILE*)&allfps, fp=allfps; fp != NULL; plast=fp, fp=fp->next ){;}
  99.   plast->next = cur_afp = makefp( NULL, 0, 0, fname );
  100.  }
  101.  
  102.  /****************************************************************************/
  103.  /* -set the csr line.                                                       */
  104.  /****************************************************************************/
  105.  if(cur_afp != NULL)
  106.  {
  107.   int LinesAvailableFromToplineToCsrline = 0;
  108.  
  109.   LinesAvailableFromToplineToCsrline = LinesPer>>1;
  110.  
  111.   if( cur_afp->csrline >= LinesAvailableFromToplineToCsrline )
  112.    cur_afp->topline = cur_afp->csrline - LinesAvailableFromToplineToCsrline + 1;
  113.   else
  114.    cur_afp->topline = 1;
  115.  }
  116.  return(cur_afp);
  117. }
  118.