~ubuntu-branches/debian/sid/mjpegtools/sid

« back to all changes in this revision

Viewing changes to utils/altivec/amber.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-09-02 16:29:46 UTC
  • Revision ID: package-import@ubuntu.com-20120902162946-i1zpl8cjngq9hd6w
Tags: upstream-2.0.0+debian
ImportĀ upstreamĀ versionĀ 2.0.0+debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* amber.c, this file is part of the
 
2
 * AltiVec optimized library for MJPEG tools MPEG-1/2 Video Encoder
 
3
 * Copyright (C) 2002  James Klicman <james@klicman.org>
 
4
 *
 
5
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include <config.h>
 
22
#endif
 
23
 
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <unistd.h>
 
27
#include <string.h>
 
28
#include <limits.h>
 
29
#ifdef HAVE_SYS_TYPES_H
 
30
#include <sys/types.h>
 
31
#endif
 
32
#include <sys/errno.h>
 
33
#include <sys/stat.h>
 
34
#include <dirent.h>
 
35
 
 
36
#include "../mjpeg_logging.h"
 
37
 
 
38
#define SIGNAL_AMBER() \
 
39
    ({register long _value; \
 
40
        asm volatile ("mfspr %0, 1023" : "=r" (_value) ); \
 
41
        _value; })
 
42
 
 
43
 
 
44
long amber_start(const char *file, int line, int *trace_count, int max_traces)
 
45
{
 
46
    long value;
 
47
 
 
48
    value = 0;
 
49
 
 
50
    if (*trace_count < max_traces) {
 
51
 
 
52
        mjpeg_info("amber start %s:%d", file, line);
 
53
 
 
54
        value = SIGNAL_AMBER();
 
55
    }
 
56
 
 
57
    return value;
 
58
}
 
59
 
 
60
long amber_stop(const char *file, int line, int *trace_count, int max_traces,
 
61
    int max_exit)
 
62
{
 
63
    long value;
 
64
 
 
65
    if (*trace_count < max_traces) {
 
66
        value = SIGNAL_AMBER();
 
67
 
 
68
        mjpeg_info("amber stop %s:%d", file, line);
 
69
 
 
70
        (*trace_count)++;
 
71
        if (max_exit && *trace_count >= max_traces)
 
72
            exit(0);
 
73
    } else {
 
74
        value = 0;
 
75
    }
 
76
 
 
77
    return value;
 
78
}
 
79
 
 
80
 
 
81
void amber_symtrace(const char *name) {
 
82
    DIR *dp;
 
83
    struct dirent *dir;
 
84
    struct stat sb;
 
85
    char tracename[PATH_MAX], sympath[PATH_MAX], symname[PATH_MAX];
 
86
    int found = 0;
 
87
 
 
88
    if ((dp = opendir(".")) == NULL)
 
89
        mjpeg_error_exit1("can't open current directory");
 
90
 
 
91
    while ((dir = readdir(dp)) != NULL) {
 
92
        if (dir->d_ino == 0)
 
93
            continue;
 
94
 
 
95
        if (strncmp(dir->d_name, "trace_", 6) == 0) {
 
96
            if (!found) {
 
97
                found = 1;
 
98
                strncpy(tracename, dir->d_name, PATH_MAX);
 
99
            } else {
 
100
                if (strncmp(dir->d_name, tracename, PATH_MAX) > 0)
 
101
                    strncpy(tracename, dir->d_name, PATH_MAX);
 
102
            }
 
103
        }
 
104
    }
 
105
    closedir(dp);
 
106
 
 
107
    if (found) {
 
108
        if (stat(name, &sb) != 0 && errno == ENOENT) {
 
109
            if (mkdir(name, 0777) != 0)
 
110
                mjpeg_error_exit1("can't make directory %s", name);
 
111
        }
 
112
        snprintf(sympath, PATH_MAX, "../%s", tracename);
 
113
        snprintf(symname, PATH_MAX, "%s/%s", name, tracename);
 
114
        if (symlink(sympath, symname) != 0)
 
115
            mjpeg_error_exit1("can't symlink %s to %s", tracename, symname);
 
116
    } else {
 
117
        mjpeg_error_exit1("trace not found");
 
118
    }
 
119
}