~ubuntu-branches/ubuntu/karmic/luatex/karmic

« back to all changes in this revision

Viewing changes to src/texk/kpathsea/kpsestat.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-05-29 04:44:18 UTC
  • mfrom: (1.1.6 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090529044418-b4d230tscam6pgt3
Tags: 0.40.2-1ubuntu1
* Merge with Debian (LP: #381539). No changes remaining.
* debian/patches/ubuntu_libpoppler-0.11: fix a FTBFS because of unuseful
  call to GfxFont destructor (virtual and protected).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* kpsestat -- show file permissions of a file in octal form.
2
 
 
3
 
   Copyright 1997, 2000, 2001, 2005 Olaf Weber.
4
 
 
5
 
   This program is free software; you can redistribute it and/or modify
6
 
   it under the terms of the GNU General Public License as published by
7
 
   the Free Software Foundation; either version 2 of the License, or
8
 
   (at your option) any later version.
9
 
 
10
 
   This program is distributed in the hope that it will be useful,
11
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
   GNU General Public License for more details.
14
 
 
15
 
   You should have received a copy of the GNU General Public License
16
 
   along with this program; if not, write to the Free Software
17
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18
 
 
19
 
*/
20
 
 
21
 
#include <kpathsea/config.h>
22
 
#include <kpathsea/c-stat.h>
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
 
26
 
/*
27
 
 *      kpsestat mode x
28
 
 *      Print stat bits of file x on stdout, as modified by mode.
29
 
 */
30
 
 
31
 
int
32
 
main P2C(int, argc, char **, argv)
33
 
{
34
 
    char * mode_string;
35
 
    int to_set, to_keep, to_clear;
36
 
    int result;
37
 
    struct stat f;
38
 
 
39
 
    if (argc > 1 && strcmp (argv[1], "--help") == 0) {
40
 
        printf ("Usage: %s MODE FILE\n\
41
 
  Print octal permissions of FILE as modified by MODE on standard output.\n\
42
 
  MODE is a subset of the symbolic permissions accepted by chmod.\n\
43
 
  Use MODE = to obtain the unchanged permissions.\n\
44
 
\n\
45
 
--help      display this help and exit\n\
46
 
--version   output version information and exit\n\n", argv[0]);
47
 
        fputs ("Email bug reports to tex-k@mail.tug.org.\n", stdout);
48
 
        exit(0);
49
 
    } else if (argc > 1 && strcmp (argv[1], "--version") == 0) {
50
 
        printf ("%s (%s)\n\
51
 
Copyright (C) 1997 Olaf Weber.\n\
52
 
There is NO warranty.  You may redistribute this software\n\
53
 
under the terms of the GNU General Public License.\n\
54
 
For more information about these matters, see the file named GPL.\n\
55
 
Primary author of %s: Olaf Weber.\n",
56
 
argv[0], KPSEVERSION, argv[0]);
57
 
        exit (0);
58
 
    }
59
 
 
60
 
    /* insist on exactly two args */
61
 
    if (argc != 3) {
62
 
        fprintf (stderr, "%s: Need exactly two arguments.\n\
63
 
Try `%s --help' for more information.\n", argv[0], argv[0]);
64
 
        exit(1);
65
 
    }
66
 
 
67
 
    mode_string = argv[1];
68
 
    to_set = to_keep = to_clear = 0;
69
 
    for (;;++mode_string) {
70
 
        int affected = 0;
71
 
        int action = 0;
72
 
        int value = 0;
73
 
 
74
 
        for (;;++mode_string)
75
 
            switch (*mode_string) {
76
 
            case 'u': affected |= 04700; break;
77
 
            case 'g': affected |= 02070; break;
78
 
            case 'o': affected |= 01007; break;
79
 
            case 'a': affected |= 07777; break;
80
 
            default: goto no_more_affected;
81
 
            }
82
 
    no_more_affected:
83
 
        if (affected == 0)
84
 
            affected = 07777;
85
 
        action = *mode_string;
86
 
        ++mode_string;
87
 
        for (;;++mode_string)
88
 
            switch (*mode_string) {
89
 
            case 'r': value |= 00444 & affected; break;
90
 
            case 'w': value |= 00222 & affected; break;
91
 
            case 'x': value |= 00111 & affected; break;
92
 
            case 's': value |= 06000 & affected; break;
93
 
            case 't': value |= 01000 & affected; break;
94
 
            default: goto no_more_values;
95
 
            }
96
 
    no_more_values:
97
 
        switch (action) {
98
 
        case '-': to_clear |= value; break;
99
 
        case '=': to_keep  |= value; break;
100
 
        case '+': to_set   |= value; break;
101
 
        default:
102
 
            fprintf(stderr, "%s: Invalid mode\n", argv[0]);
103
 
            exit(1);
104
 
        }
105
 
        if (*mode_string != ',')
106
 
            break;
107
 
    }
108
 
    if (*mode_string != 0) {
109
 
        fprintf(stderr, "%s: Invalid mode.\n", argv[0]);
110
 
        exit(1);
111
 
    }
112
 
 
113
 
    /* does the file exist? */
114
 
    if (stat (argv[2], &f) < 0) {
115
 
        fprintf(stderr, "%s: ", argv[0]);
116
 
        perror(argv[2]);
117
 
        return 1;
118
 
    }
119
 
   
120
 
    result = f.st_mode & 07777;
121
 
    result |= to_set;
122
 
    result |= to_keep & result;
123
 
    result &= ~to_clear;
124
 
 
125
 
    printf("%o\n", result);
126
 
 
127
 
    return 0;
128
 
}