OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [AS64/] [source/] [SEARCHEN.Cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2014  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
// A64 - Assembler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify
12
// it under the terms of the GNU Lesser General Public License as published
13
// by the Free Software Foundation, either version 3 of the License, or
14
// (at your option) any later version.
15
//
16
// This source file is distributed in the hope that it will be useful,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
// GNU General Public License for more details.
20
//
21
// You should have received a copy of the GNU General Public License
22
// along with this program.  If not, see .
23
//
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
/* ---------------------------------------------------------------------------
29
   void searchenv(filename, envname, pathname);
30
   char *filename;
31
   char *envname;
32
   char **pathname;
33
 
34
   Description :
35
      Search for a file by looking in the directories listed in the envname
36
   environment. Puts the full path name (if you find it) into pathname.
37
   Otherwise set *pathname to 0.
38
 
39
   Returns :
40
      nothing
41
--------------------------------------------------------------------------- */
42
 
43
void searchenv(char *filename, char *envname, char **pathname)
44
{
45
   static char pbuf[5000];
46
   static char pname[5000];
47
   char *p;
48
//   char *strpbrk(), *strtok(), *getenv();
49
 
50
    if (pathname==(char **)NULL)
51
        return;
52
   strncpy(pname, filename, sizeof(pname)/sizeof(char)-1);
53
   pname[4999] = '\0';
54
   if (access(pname, 0) != -1) {
55
      *pathname = strdup(pname);
56
      return;
57
   }
58
 
59
   /* ----------------------------------------------------------------------
60
         The file doesn't exist in the current directory. If a specific
61
      path was requested (ie. file contains \ or /) or if the environment
62
      isn't set, return a NULL, else search for the file on the path.
63
   ---------------------------------------------------------------------- */
64
 
65
   if (!(p = getenv(envname)))
66
   {
67
      *pathname = strdup("");
68
      return;
69
   }
70
 
71
   strcpy(pbuf, "");
72
   strcat(pbuf, p);
73
   if (p = strtok(pbuf, ";"))
74
   {
75
      do
76
      {
77
         sprintf(pname, "%0.4999s\\%s", p, filename);
78
 
79
         if (access(pname, 0) >= 0) {
80
            *pathname = strdup(pname);
81
            return;
82
         }
83
      }
84
      while(p = strtok(NULL, ";"));
85
   }
86
   *pathname = strdup("");
87
}
88
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.