File: vmsfile.c

package info (click to toggle)
tin 981002-2
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 3,088 kB
  • ctags: 4,969
  • sloc: ansic: 46,800; sh: 1,655; makefile: 1,144; yacc: 699; perl: 103
file content (82 lines) | stat: -rw-r--r-- 1,705 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <string.h>
#include <stdio.h>
#include "parse.h"

#if 0
extern char *strdup();

char **split(char *spliton, char *target)
{
  static char *buffer[100];
  static char *t = 0;
  char **p;

  if (t)
    free(t);


  while ((t = strdup(target)) == NULL)
    sleep(2);			/* just wait for out of memory condition
				   to go away */

  for (p = &buffer[0], *p = strtok(t, spliton);
       *p;
       *(++p) = strtok(NULL, spliton)) ;

  return buffer;
}
#endif

void joinpath(char *result, const char *dir, const char *file)
{
  struct filespec *spec;
  char tmpdir[255], tmpfile[255];
  char *ptr1, *ptr2;

  strcpy(tmpdir, dir);
  strcpy(tmpfile, file);

  if (strlen (tmpdir) == 0) {
    strcpy (result, tmpfile);
    return;
  }
  if (tmpfile[0] == '[')
   {
    strcat(tmpdir,tmpfile);
    tmpfile[0] = '\0';
   }
  spec = sysparse(tmpdir);
  sprintf(result, "%s%s%s", spec->dev, spec->dir, tmpfile);
  if (spec->filename[0]) {
    fprintf(stderr, "joinpath: throwing away filename %s\n", spec->filename);
  }
}

void joindir(char *result, const char *dir, const char *file)
{
  struct filespec *spec;
  int i;
  char tmpdir[255], tmpfile[255];

  strcpy(tmpdir, dir);
  strcpy(tmpfile, file);

  if (strlen (tmpdir) == 0) {
    sprintf(result, "[%s]", tmpfile);
    return;
  }
  spec = sysparse(tmpdir);
  i = strlen(spec->dir);
  if (spec->dir[i-1] == ']') {
    spec->dir[i-1] = 0;
    sprintf(result, "%s%s.%s]", spec->dev, spec->dir, tmpfile);
    if (spec->filename[0]) {
      fprintf(stderr, "joinpath: throwing away filename %s\n", spec->filename);
    }
  } else {
    fprintf(stderr, "joinpath: dir %s didn't end with ']' (passed %s)\n",
	    spec->dir, tmpfile);
    exit(0);
  }
}