File: c_args.c

package info (click to toggle)
cufflinks 1.3.0-2
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 3,864 kB
  • sloc: cpp: 48,999; ansic: 12,297; sh: 3,381; python: 432; makefile: 209
file content (89 lines) | stat: -rw-r--r-- 1,798 bytes parent folder | download | duplicates (5)
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
83
84
85
86
87
88
89
/*
 *   Copyright (c) 1996-2000 Lucent Technologies.
 *   See README file for details.
 *
 *   Functions for interpreting and manipulating command line
 *   arguments.
 */

#include "local.h"

char *argval(vari *v,int i)
{ if (i<0) return(NULL);
  return(((carg *)viptr(v,i))->val);
}

int getarg(v,s,un) /* un=1: unnamed permitted un=2: next unused */
vari *v;
int un;
char *s;
{ int i;
  if (un==2)
  { for (i=1; i<vlength(v); i++)
    { if (!argused(v,i))
      { setused(v,i);
        return(i);
      }
    }
    return(0);
  }
  for (i=1; i<vlength(v); i++)
  { if ((!argused(v,i)) && (argarg(v,i)!=NULL))
    { if (strcmp(argarg(v,i),s)==0)
      { setused(v,i);
        return(i);
      }
    }
  }
  if (!un) return(0);
  for (i=1; i<vlength(v); i++)
  { if ((!argused(v,i)) && (argarg(v,i)==NULL))
    { setused(v,i);
      return(i);
    }
  }
  return(0);
}

char *getargval(vari *v, char *s, int un)
{ int i;
  i = getarg(v,s,un);
  if (i==0) return(NULL);
  return(argval(v,i));
}

int readilist(ivec,z,n0,n1,pad)
char *z;
int *ivec, n0, n1, pad;
{ int i, n, nd;
  n = 1;
  for (i=0; i<strlen(z); i++)
    if (z[i]==',') { z[i]=' '; n++; }
  if (n>n1)
  { WARN(("too many items in ilist"));
    n = n1;
  }
  for (i=0; i<n; i++)
  { nd = sscanf(z,"%d",&ivec[i]);
    //if (nd!=1) WARN(("problem scaning ilist %s",&ivec[i]));
    if (i<n-1) while (*z!=' ') z++;
  }
  if (pad)
  { for (i=n; i<n1; i++) ivec[i] = ivec[0]; 
    n = n1;
  }
  if (n<n0) WARN(("too few items in ilist"));
  return(n);
}

int getlogic(v,i)
vari *v;
int i;
{ char *z;
  if (argarg(v,i)==NULL) return(1);
  z = argval(v,i);
  if ((z[0]=='T') | (z[0]=='t') | (z[0]=='1')) return(1);
  if ((z[0]=='F') | (z[0]=='f') | (z[0]=='0')) return(0);
  ERROR(("getlogic: invalid logical argument %s",z));
  return(0);
}