repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
|---|---|---|
starmuse/PROJBASEClasses
|
PROJBASEClasses/Classes/BaseTableViewController/PROJTableViewModel.h
|
//
// PROJTableViewModel.h
// PROJProjectA
//
// Created by 1 on 10/1/20.
// Copyright © 2020 hausinTec. All rights reserved.
//
// 依赖 YYModel
#import <UIKit/UIKit.h>
#import <YYKit/NSObject+YYModel.h>
@class PROJTableViewSectionModel;
@class PROJTableViewSectionInfoModel;
@class PROJTableViewSectionHeaderFooterModel;
@class PROJTableViewCellModel;
NS_ASSUME_NONNULL_BEGIN
///--------------------------------------------
/// @name PROJTableViewModel
///--------------------------------------------
// 用于描述整个 tableview
@interface PROJTableViewModel : NSObject<YYModel>
@property (nonatomic, strong) id headerModel;
@property (nonatomic, strong) NSMutableArray<PROJTableViewSectionModel *> *sectionModels;
@property (nonatomic, strong) id footerModel;
@end
///--------------------------------------------
/// @name PROJTableViewModel
///--------------------------------------------
// 用于描述整个 section
@interface PROJTableViewSectionModel : NSObject
@property (nonatomic, strong) __kindof PROJTableViewSectionInfoModel *info;
@property (nonatomic, strong) __kindof PROJTableViewSectionHeaderFooterModel *header;
@property (nonatomic, strong) NSMutableArray<PROJTableViewCellModel *> *cells;
@property (nonatomic, strong) __kindof PROJTableViewSectionHeaderFooterModel *footer;
@end
///--------------------------------------------
/// @name PROJTableViewModel
///--------------------------------------------
// 用于描述 section 的基本信息
@interface PROJTableViewSectionInfoModel : NSObject
@property (nonatomic, copy) NSString *sectionID;
@property (nonatomic, copy) NSString *sectionTitle;
@property (nonatomic, copy) NSString *flag;
@property (nonatomic, strong) id data;
@end
///--------------------------------------------
/// @name PROJTableViewModel
///--------------------------------------------
// 用于描述 section 的 header/footer
@interface PROJTableViewSectionHeaderFooterModel : NSObject
@property (nonatomic, copy) NSString *headerFooter_class;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *flag;
@property (nonatomic, strong) id data;
@end
///--------------------------------------------
/// @name PROJTableViewModel
///--------------------------------------------
// 用于描述整个 cell
@interface PROJTableViewCellModel : NSObject
@property (nonatomic, copy) NSString *cell_class;
@property (nonatomic, copy) NSString *destination_controller;
@property (nonatomic, strong) id server_model;
@property (nonatomic, strong) id viewModel;
@end
NS_ASSUME_NONNULL_END
|
starmuse/PROJBASEClasses
|
Example/Pods/Target Support Files/PROJBASEClasses/PROJBASEClasses-umbrella.h
|
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#import "PROJBaseTableViewCell.h"
#import "PROJBaseTableViewController.h"
#import "PROJBaseTableViewHeaderFooterView.h"
#import "PROJTableViewModel.h"
#import "PROJBaseViewController.h"
FOUNDATION_EXPORT double PROJBASEClassesVersionNumber;
FOUNDATION_EXPORT const unsigned char PROJBASEClassesVersionString[];
|
starmuse/PROJBASEClasses
|
Example/PROJBASEClasses/PROJViewController.h
|
//
// PROJViewController.h
// PROJBASEClasses
//
// Created by keith on 12/20/2020.
// Copyright (c) 2020 keith. All rights reserved.
//
@import UIKit;
@interface PROJViewController : UIViewController
@end
|
starmuse/PROJBASEClasses
|
PROJBASEClasses/Classes/PROJBaseViewController.h
|
<reponame>starmuse/PROJBASEClasses
//
// PROJBaseViewController.h
// Keith2020FeedsAppN01
//
// Created by 1 on 12/9/20.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface PROJBaseViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
|
chucknthem/Data-structures-algorithms
|
algorithms/prime_sieve.c
|
<gh_stars>1-10
#include <stdio.h>
#include <malloc.h>
int nextPrime(int i, char *sieve, int max) {
while(i < max && !sieve[i]) {
i++;
}
return i;
}
void setNotPrime(int i, char *sieve, int max) {
int j;
for(j = i; j < max; j += i) {
sieve[j] = 0;
}
}
int main(int argc, char**argv) {
int n = atoi(argv[1]);
char *sieve = (char*) malloc(sizeof(char));
int i;
for(i = 0; i < n; i++) {
sieve[i] = 1;
}
for(i = 2; i < n; i = nextPrime(i, sieve, n)) {
printf("%d ", i);
setNotPrime(i, sieve, n);
}
return 0;
}
|
chucknthem/Data-structures-algorithms
|
algorithms/gcd.c
|
<reponame>chucknthem/Data-structures-algorithms
#include <stdio.h>
/*
* Eulers algorithm for calculating the greatest common divisor of two numbers.
*
* gcd(a, b) is the largest number that divides both a and b. If that number is 1, then a and b
* are co-prime.
*
* Euler discovered that gcd(a, b) = gcd(a - b, b) if a > b and gcd(a, b) = gcd(a, b - a) if b > a
* Which gives us a very fast way of calculating the gcd without doing any prime factoring.
*/
int gcd(int a, int b) {
if (a == 0) return b;
if (b == 0) return a;
if (a > b) return gcd(a - b, b);
return gcd(a, b - a);
}
int main(void) {
printf("gcd(%d, %d) = %d\n", 124, 1262, gcd(144, 122334));
return 0;
}
|
chucknthem/Data-structures-algorithms
|
algorithms/sorting/quicksort.c
|
<filename>algorithms/sorting/quicksort.c
#include <stdio.h>
#include <malloc.h>
void printArray(int *array, int low, int high) {
while(low <= high) {
printf("%d ", array[low++]);
}
printf("\n");
}
void swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
/*
* * pick a pivot index between low and high inclusive
* */
int getPivot(int *array, int low, int high) {
return low;
}
/*
* * @return the position of the pivot
* */
int partition(int *array, int low, int high, int pivot) {
int cur = low;
swap(&array[pivot], &array[high]);
while (low <= high) {
if(array[low] < array[high]) {
swap(&array[low], &array[cur]);
cur++;
}
low++;
}
swap(&array[cur], &array[high]);
return cur;
}
void qsortLH(int *array, int low, int high) {
if(low < high) {
int pivot = getPivot(array, low, high);
pivot = partition(array, low, high, pivot);
qsortLH(array, low, pivot - 1);
qsortLH(array, pivot + 1, high);
}
}
int main(int argc, char**argv) {
int *array = (int *) malloc(sizeof(int)*8);
array[0] = 1;
array[1] = 4;
array[2] = 6;
array[3] = 58;
array[4] = 4;
array[5] = 2;
array[6] = 7;
array[7] = 23;
printArray(array, 0, 7);
qsortLH(array, 0, 7);
printArray(array, 0, 7);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
misc/bit_addition.c
|
#include <stdio.h>
/**
* This function implements the addition operation using only bit operators.
*/
int add(int a, int b) {
int c = a & b;
while (a != 0) {
c = b & a;
b = b ^ a;
c = c << 1;
a = c;
}
return b;
}
int main() {
printf("%d\n", add(51, 152)); // 203
}
|
chucknthem/Data-structures-algorithms
|
misc/base.c
|
#include <stdio.h>
#include <malloc.h>
#include <assert.h>
void swap(char *c1, char *c2) {
char tmp = *c1;
*c1 = *c2;
*c2 = tmp;
}
void reverse(char *str, int max) {
int i;
for (i = 0; i <= max/2; i++) {
swap(&str[i], &str[max - i]);
}
}
char *alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/*
* decimal to base, up to a base of strlen(alpha)
*/
char *dec2base(float dec, int base) {
assert (base <= 36);
int mant = dec;
float deci = dec - mant;
char *bStr = (char*) malloc(sizeof(char)*50);
int i = 0;
while (mant > 0) {
bStr[i++] = alpha[mant % base];
mant /= base;
}
reverse(bStr, i - 1);
if(deci > 0) bStr[i++] = '.';
while (deci > 0) {
deci *= base;
bStr[i++] = alpha[(int)deci];
deci -= (int)deci;
}
bStr[i] = '\0';
return bStr;
}
int main(void) {
float num;
int base;
scanf("%f %d", &num, &base);
char *bin = dec2base(num, base);
printf("%s\n", bin);
free(bin);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
algorithms/reverse_words.c
|
<reponame>chucknthem/Data-structures-algorithms<gh_stars>1-10
#include <stdio.h>
#include <string.h>
#include <ctype.h>
/*
* Reverse the order of words in a string in place.
*
* 1. Reverse the string.
* 2. Reverse each word in the string.
*/
void reverse(char* str, int i, int j) {
char tmp;
for (; i < j; i++, j--) {
tmp = str[i];
str[i] = str[j];
str[j] = tmp;
}
}
/*
* Find the end of a word from the start position
*/
int wordEnd(char* str, int start, int len) {
int i = start;
while (i < len) {
if (!isalpha(str[i]) && !isdigit(str[i])) {
return i - 1;
}
i++;
}
return start;
}
int main(int argc, char** argv) {
char* str = argv[1];
char* dup = strdup(str);
int len = strlen(str);
reverse(str, 0, len - 1);
int start = 0;
int end;
while (start < len) {
if (isalpha(str[start]) || isdigit(str[start])) {
end = wordEnd(str, start, len);
reverse(str, start, end);
start = end;
}
start++;
}
printf("\"%s\" reversed is \"%s\"\n", dup, str);
free(dup);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
structs/linked_list.c
|
<filename>structs/linked_list.c
#include <stdio.h>
#include <stdlib.h>
#include <malloc/malloc.h>
#define INVALID_VALUE -1
typedef struct NodeT {
struct NodeT* next;
int value;
} Node;
typedef struct ListT {
Node* head;
int length;
} List;
List* createList() {
List* newList = (List*) malloc(sizeof(List));
newList->head = NULL;
newList->length = 0;
return newList;
}
Node* createNode(int value) {
Node* newNode = (Node*) malloc(sizeof(Node));
newNode->next = NULL;
newNode->value = value;
return newNode;
}
void destroyNode(Node* node) {
free(node);
}
void destroyList(List* list) {
if (!list) return;
while (list->head) {
Node* next = list->head->next;
free(list->head);
list->head = next;
}
free(list);
}
/**
* Insert value at position. The list is zero indexed.
*/
void insertNode(List* ls, int value, int position) {
Node* newNode = createNode(value);
if (position == 0 || ls->head == NULL) {
newNode->next = ls->head;
ls->head = newNode;
}
Node* cur = ls->head;
Node* prev = NULL;
while(position-- && cur)
prev = cur;
cur = cur->next;
newNode->next = cur;
prev->next = newNode;
ls->length++;
}
/**
* Delete the node at position where position starts at 0.
*/
void removeNode(List* ls, int position) {
if (position >= ls->length) return;
Node* cur = ls->head;
Node* prev = NULL;
if (position == 0) {
ls->head = ls->head->next;
} else {
// Find the node to delete.
for(; cur && position; position--, cur = cur->next)
prev = cur;
prev->next = cur->next;
}
free(cur);
ls->length--;
}
void push(List* ls, int value) {
Node* newNode = createNode(value);
newNode->next = ls->head;
ls->head = newNode;
ls->length++;
}
void pushNode(List* ls, Node* node) {
node->next = ls->head;
ls->head = node;
ls->length++;
}
int pop(List* ls) {
Node* node = ls->head;
int value = INVALID_VALUE;
if (node) {
ls->head = node->next;
ls->length--;
value = node->value;
destroyNode(node);
}
return value;
}
Node* popNode(List* ls) {
Node* node = ls->head;
if (node) {
ls->head = node->next;
ls->length--;
}
return node;
}
/*
* What is the reverse of null (the empty list)? null.
* What is the reverse of a one element list? the element.
* What is the reverse of an n element list? the reverse of the second element on followed by the first element.
*/
Node* reverseRecursiveNodeList(Node* node) {
if (!(node && node->next)) return node;
Node* next = node->next;
node->next = NULL;
Node* rest = reverseRecursiveNodeList(next);
next->next = node;
return rest;
}
Node* reverseNodeList(Node* node) {
if (!(node && node->next))
return node;
Node* cur = node;
Node* next = node->next;
node->next = NULL;
Node* tmp;
while (next) {
tmp = next->next;
next->next = cur;
cur = next;
next = tmp;
}
return cur;
}
void reverseRecursive(List* ls) {
ls->head = reverseRecursiveNodeList(ls->head);
}
void reverse(List* ls) {
ls->head = reverseNodeList(ls->head);
}
void printList(List* list) {
Node* current;
for (current = list->head; current != NULL; current = current->next) {
printf("%d ", current->value);
}
putchar('\n');
}
int main(void) {
List* list = createList();
push(list, 4);
push(list, 8);
push(list, 1);
push(list, 9);
push(list, 3);
push(list, 5);
push(list, 8);
push(list, 7);
printf("starting list\n");
printList(list);
int top = pop(list);
printf("popped %d\n", top);
printList(list);
reverse(list);
printf("iterative reverse\n");
printList(list);
reverseRecursive(list);
printf("recursive reverse\n");
printList(list);
destroyList(list);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
algorithms/sorting/bubble.c
|
<filename>algorithms/sorting/bubble.c
#include <stdio.h>
void swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
/*
* Bubble sort with early exit.
*
* for i from n - 1 to 0 (inclusive)
* for j from 0 to i - 2 (inclusive)
* if(j > j+1) swap(j, j+1)
*/
void bubble(int array[], int length) {
int i,j;
int isSorted = 0;
for(i = length - 1; i >= 0 && !isSorted; i--) {
isSorted = 1;
for(j = 0; j < i; j++) {
if(array[j] > array[j+1]) {
isSorted = 0;
swap(&array[j], &array[j+1]);
}
}
}
}
/*
* Naive bubble sort.
*/
void bubblen(int array[], int length) {
int i,j;
int isSorted = 0;
for(i = length - 1; i >= 0 && !isSorted; i--) {
for(j = 0; j < i; j++) {
if(array[j] > array[j+1]) {
swap(&array[j], &array[j+1]);
}
}
}
}
/*
* Print Array.
*/
void printa(int array[], int len) {
int j;
for(j = 0; j < len; j++) {
printf("%d ", array[j]);
}
printf("\n");
}
int main(void) {
int array[10] = {3, 5, 1, 4, 5, 2, 4, 7, 12, 13};
printa(array, 10);
bubble(array, 10);
printa(array, 10);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
algorithms/sorting/selection.c
|
#include <stdio.h>
void swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
/*
* Selection sort.
*
* for i = 0..(n-1)
* min = i
* for j = i+1..(n-1)
* if(a[min] > a[j]) a[min] = a[j]
* swap(a[min], a[j])
*/
void selection(int a[], int length) {
int i, j, min;
for (i = 0; i < length; i++){
min = i;
for (j = i + 1; j < length; j++){
if(a[min] > a[j]) {
a[min] = a[j];
}
}
swap(&a[min], &a[i]);
}
}
/*
* Print Array.
*/
void printa(int array[], int len) {
int j;
for(j = 0; j < len; j++) {
printf("%d ", array[j]);
}
printf("\n");
}
int main(void) {
int array[10] = {3, 5, 1, 4, 5, 2, 4, 7, 12, 13};
printa(array, 10);
selection(array, 10);
printa(array, 10);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
structs/binary_search_tree.c
|
<gh_stars>1-10
#include <stdio.h>
#include <stdlib.h>
#include <malloc/malloc.h>
#include <assert.h>
typedef struct NodeT {
int height;
int size;
int value;
struct NodeT* left;
struct NodeT* right;
} Node;
typedef struct TreeT {
Node* root;
int height;
int size;
} Tree;
Tree* createTree();
void destroyTree(Tree* tree);
Node* createNode();
void destroyNode(Node* node);
Node* insertNode(Node* root, Node* node);
void insert(Tree* tree, int value);
void prefixWalkNode(Node* root, void (*walk) (Node* node));
void infixWalkNode(Node* root, void (*walk) (Node* node));
void postfixWalkNode(Node* root, void (*walk) (Node* node));
void printNode(Node* node);
Tree* createTree() {
Tree* tree = (Tree*)malloc(sizeof(Tree));
tree->height = 0;
tree->size = 0;
return tree;
}
void destroyTree(Tree* tree) {
postfixWalkNode(tree->root, destroyNode);
free(tree);
}
Node* createNode(int value) {
Node* node = (Node*)malloc(sizeof(Node));
node->value = value;
node->left = NULL;
node->right = NULL;
node->height = 1;
node->size = 1;
return node;
}
void destroyNode(Node* node) {
free(node);
}
int calcSize1Level(Node* node) {
if (node->left && node->right) {
return 1 + node->left->height + node->right->height;
}
if (node->left) {
return 1 + node->left->size;
}
if (node->right) {
return 1 + node->right->size;
}
return 1;
}
int calcHeight1Level(Node* node) {
if (node->left && node->right) {
return 1 + (node->left->value < node->right->value)? node->right->height : node->left->height;
}
if (node->left) {
return 1 + node->left->height;
}
if (node->right) {
return 1 + node->right->height;
}
return 1;
}
Node* insertNode(Node* root, Node* node) {
if (!root)
return node;
if (node->value <= root->value) {
root->left = insertNode(root->left, node);
} else {
root->right = insertNode(root->right, node);
}
root->height = calcHeight1Level(root);
root->size = calcSize1Level(root);
return root;
}
void insert(Tree* tree, int value) {
Node* newNode = createNode(value);
tree->root = insertNode(tree->root, newNode);
tree->height = tree->root->height;
tree->size = tree->root->size;
}
void prefixWalkNode(Node* root, void (*walk) (Node* node)) {
if (root == NULL) return;
walk(root);
prefixWalkNode(root->left, walk);
prefixWalkNode(root->right, walk);
}
void infixWalkNode(Node* root, void (*walk) (Node* node)) {
if (root == NULL) return;
infixWalkNode(root->left, walk);
walk(root);
infixWalkNode(root->right, walk);
}
void postfixWalkNode(Node* root, void (*walk) (Node* node)) {
if (root == NULL) return;
postfixWalkNode(root->left, walk);
postfixWalkNode(root->right, walk);
walk(root);
}
Node* find(Node* node, int value) {
if (!node) return NULL;
if (node->value == value) return node;
Node* found;
found = find(node->left, value);
if (found) return found;
return find(node->right, value);
}
void printNode(Node* node) {
printf("%d ", node->value);
}
int main(void) {
Tree* tree = createTree();
insert(tree, 4);
insert(tree, 1);
insert(tree, 5);
insert(tree, 2);
insert(tree, 0);
insert(tree, 9);
insert(tree, 2);
insert(tree, 3);
insert(tree, 1);
insert(tree, 8);
prefixWalkNode(tree->root, printNode);
putchar('\n');
infixWalkNode(tree->root, printNode);
putchar('\n');
postfixWalkNode(tree->root, printNode);
putchar('\n');
assert(find(tree->root, 5));
assert(find(tree->root, 1));
assert(find(tree->root, 8));
assert(!find(tree->root, 1008));
assert(!find(tree->root, -18));
destroyTree(tree);
return 0;
}
|
chucknthem/Data-structures-algorithms
|
algorithms/atoi_string_to_integer.c
|
#include <stdio.h>
#include <string.h>
#include <assert.h>
int main(int argc, char** argv) {
char* str = argv[1];
int sum = 0;
int len = strlen(str);
int i;
for (i = 0; i < len; i++) {
assert(str[i] >= '0' && str[i] <= '9');
sum = sum * 10 + str[i] - '0';
}
printf("%d\n", sum);
return 0;
}
|
b2wads/flamegraph-profiler
|
src/native/fold_profile.h
|
<filename>src/native/fold_profile.h
#pragma once
#include <v8-profiler.h>
#include <list>
#include <sstream>
namespace flamegraph_profiler {
void collapse_recursively (std::stringstream& output, const v8::CpuProfileNode* node, std::string function_trace, unsigned chars_to_trim);
std::list<const v8::CpuProfileNode*> cut_branches_at_root(const v8::CpuProfileNode* node, const std::string& root);
}
|
b2wads/flamegraph-profiler
|
src/native/profile_converter.h
|
<gh_stars>0
#pragma once
#include <string>
#include <v8-profiler.h>
#include <nan.h>
#include <sstream>
namespace flamegraph_profiler {
class profile_converter : public Nan::AsyncWorker {
private:
v8::CpuProfile* profile;
std::string root_script;
std::stringstream folded_profile;
unsigned chars_to_trim;
public:
profile_converter(v8::CpuProfile* profile, Nan::Callback* callback, const std::string& root_script, unsigned chars_to_trim);
void Execute();
void HandleOKCallback();
void HandleErrorCallback();
};
}
|
b2wads/flamegraph-profiler
|
src/native/cpu_profiler.h
|
<reponame>b2wads/flamegraph-profiler
#pragma once
#include <nan.h>
namespace flamegraph_profiler {
void Initialize(v8::Local<v8::Object> exports);
void setSamplingInterval(const Nan::FunctionCallbackInfo<v8::Value>& args);
void start(const Nan::FunctionCallbackInfo<v8::Value>& args);
void stop(const Nan::FunctionCallbackInfo<v8::Value>& args);
NODE_MODULE(cpu_profiler, Initialize);
}
|
Reedyuk/realm-kotlin
|
packages/cinterop/src/jvm/jni/utils.h
|
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
#include <realm/string_data.hpp>
#include <realm/table.hpp>
#include "env_utils.h"
using namespace realm;
jstring to_jstring(JNIEnv* env, realm::StringData str);
class JStringAccessor {
public:
JStringAccessor(JNIEnv* env, jstring s) : JStringAccessor(env, s, false) {}; // throws
JStringAccessor(JNIEnv*, jstring, bool); // throws
bool is_null_or_empty() {
return m_is_null || m_size == 0;
}
bool is_null() {
return m_is_null;
}
operator realm::StringData() const
{
// To solve the link issue by directly using Table::max_string_size
static constexpr size_t max_string_size = realm::Table::max_string_size;
if (m_is_null) {
return realm::StringData();
}
else if (m_size > max_string_size) {
throw util::runtime_error(realm::util::format(
"The length of 'String' value in UTF8 encoding is %1 which exceeds the max string length %2.",
m_size, max_string_size));
}
else {
return realm::StringData(m_data.get(), m_size);
}
}
operator std::string() const noexcept
{
if (m_is_null) {
return std::string();
}
return std::string(m_data.get(), m_size);
}
private:
JNIEnv* m_env;
bool m_is_null;
std::shared_ptr<char> m_data;
std::size_t m_size;
};
// Accessor for Java object arrays
template <typename AccessorType, typename ObjectType>
class JObjectArrayAccessor {
public:
JObjectArrayAccessor(JNIEnv* env, jobjectArray jobject_array)
: m_env(env)
, m_jobject_array(jobject_array)
, m_size(jobject_array ? env->GetArrayLength(jobject_array) : 0)
{
}
~JObjectArrayAccessor()
{
}
// Not implemented
JObjectArrayAccessor(JObjectArrayAccessor&&) = delete;
JObjectArrayAccessor& operator=(JObjectArrayAccessor&&) = delete;
JObjectArrayAccessor(const JObjectArrayAccessor&) = delete;
JObjectArrayAccessor& operator=(const JObjectArrayAccessor&) = delete;
inline jsize size() const noexcept
{
return m_size;
}
inline AccessorType operator[](const int index) const noexcept
{
return AccessorType(m_env, static_cast<ObjectType>(m_env->GetObjectArrayElement(m_jobject_array, index)));
}
private:
JNIEnv* m_env;
jobjectArray m_jobject_array;
jsize m_size;
};
template<>
inline JStringAccessor JObjectArrayAccessor<JStringAccessor,jstring>::operator[](const int index) const noexcept {
return JStringAccessor(m_env, static_cast<jstring>(m_env->GetObjectArrayElement(m_jobject_array, index)), true);
}
#endif //TEST_UTILS_H
|
Reedyuk/realm-kotlin
|
packages/jni-swig-stub/src/main/jni/realm_api_helpers.h
|
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_REALM_API_HELPERS_H
#define TEST_REALM_API_HELPERS_H
#include "realm.h"
#include "env_utils.h"
#include "java_class_global_def.hpp"
#include "utils.h"
realm_notification_token_t*
register_results_notification_cb(realm_results_t *results, jobject callback);
realm_notification_token_t*
register_list_notification_cb(realm_list_t *list, jobject callback);
realm_notification_token_t*
register_object_notification_cb(realm_object_t *object, jobject callback);
realm_http_transport_t*
realm_network_transport_new(jobject network_transport);
void
set_log_callback(realm_sync_client_config_t* sync_client_config, jobject log_callback);
realm_t*
open_realm_with_scheduler(int64_t config_ptr, jobject dispatchScheduler);
void
invoke_core_notify_callback(int64_t core_notify_function);
void app_complete_void_callback(void* userdata, const realm_app_error_t* error);
void app_complete_result_callback(void* userdata, void* result, const realm_app_error_t* error);
void
sync_set_error_handler(realm_sync_config_t* sync_config, jobject error_handler);
void
complete_http_request(void* request_context, jobject j_response);
#endif //TEST_REALM_API_HELPERS_H
|
Reedyuk/realm-kotlin
|
packages/cinterop/src/jvm/jni/env_utils.h
|
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_ENV_UTILS_H
#define TEST_ENV_UTILS_H
#include <jni.h>
#include <cstring>
#include <string>
#include <vector>
#include "java_global_ref_by_move.hpp"
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved);
namespace realm {
namespace jni_util {
static std::vector<JavaGlobalRefByMove> m_global_refs;
JNIEnv * get_env(bool attach_if_needed = false);
// Returns current environment (or attaches current thread) or returns null if not possible
// to obtain an environment, in which case we assume that the VM has shut down;
JNIEnv * get_env_or_null();
// TODO Migrate java_method.{hpp,cpp} realm-java or implement similar caching mechanism to
// hold global references to classes and look up methods
jmethodID lookup(JNIEnv *jenv, const char *class_name, const char *method_name,
const char *signature);
void keep_global_ref(JavaGlobalRefByMove& ref);
}
}
#endif //TEST_ENV_UTILS_H
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/NSMutableDictionary+ETRUtils.h
|
<gh_stars>0
//
// NSMutableDictionary+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSMutableDictionary (ETRUtils)
- (void)etr_safeSetObject:(id)object
forKey:(id<NSCopying>)key;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/UIActivityIndicatorView+ETRUtils.h
|
<reponame>Vadim-Yelagin/ETRUtils<gh_stars>0
//
// UIActivityIndicatorView+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UIActivityIndicatorView (ETRUtils)
@property (nonatomic, readwrite, getter = isAnimating) BOOL animating;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/ETRUtils/CPDViewController.h
|
//
// ETRViewController.h
// ETRUtils
//
// Created by <NAME> on 01/14/2015.
// Copyright (c) 2014 <NAME>. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ETRViewController : UIViewController
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/UIColor+ETRUtils.h
|
<reponame>Vadim-Yelagin/ETRUtils
//
// UIColor+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UIColor (ETRUtils)
+ (UIColor *)etr_colorWithHex:(uint32_t)hex;
+ (UIColor *)etr_colorWithHexString:(NSString *)hex;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/NSMutableArray+ETRUtils.h
|
//
// NSMutableArray+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSMutableArray (ETRUtils)
- (void)etr_safeAdd:(id)object;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/UITableView+ETRUtils.h
|
<reponame>Vadim-Yelagin/ETRUtils<gh_stars>0
//
// UITableView+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UITableView (ETRUtils)
- (void)etr_deselectAllRowsAnimated:(BOOL)animated;
- (void)etr_reloadDataKeepingSelection;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/ETRImagePickerController.h
|
//
// ETRImagePickerController.h
//
// Created by <NAME> on 27/02/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface ETRImagePickerController : UIImagePickerController
+ (void)presentImagePickerWithSourceType:(UIImagePickerControllerSourceType)sourceType
sender:(UIView *)sender
parent:(UIViewController *)viewController
completion:(void (^)(UIImage *))completion;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/ETRCGUtils.h
|
<reponame>Vadim-Yelagin/ETRUtils<filename>Example/Pods/Headers/Public/ETRUtils/ETRCGUtils.h<gh_stars>0
//
// ETRCGUtils.h
//
// Created by <NAME> on 03/12/13.
// Copyright (c) 2013 EastBanc Technologies Russia. All rights reserved.
//
@import CoreGraphics;
@import Foundation;
extern CGPoint ETRPointAdd(CGPoint a, CGPoint b);
extern CGPoint ETRPointSub(CGPoint a, CGPoint b);
extern CGPoint ETRPointNeg(CGPoint a);
extern CGFloat ETRPointDot(CGPoint a, CGPoint b);
extern CGFloat ETRPointCross(CGPoint a, CGPoint b);
extern CGPoint ETRPointMul(CGFloat a, CGPoint b);
extern NSComparisonResult ETRSign(CGFloat a);
@interface NSArray (ETRCGUtils)
- (NSArray*)convexHull;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/UIImage+ETRUtils.h
|
<gh_stars>0
//
// UIImage+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UIImage (ETRUtils)
- (CGAffineTransform)etr_affineTransformToCGImage;
+ (UIImage*)etr_imageWithSize:(CGSize)size
opaque:(BOOL)opaque
scale:(CGFloat)scale
graphics:(void(^)(CGContextRef ctx))graphics;
- (UIImage*)etr_imageTintedWithColor:(UIColor*)color;
- (UIImage*)etr_imageWithAlpha:(CGFloat)alpha;
- (UIImage*)etr_imageStretchedToSize:(CGSize)size;
- (UIImage*)etr_imageThumbWithMaxSize:(CGSize)maxSize
scale:(CGFloat)scale;
- (UIImage*)etr_imageCroppedToRect:(CGRect)rect;
+ (UIImage*)etr_imageWithColor:(UIColor*)color
size:(CGSize)size;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/ETRActionSheet.h
|
//
// ETRActionSheet.h
//
// Created by <NAME> on 01/11/13.
// Copyright (c) 2013 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface ETRActionSheet : UIActionSheet
+ (instancetype)actionSheet;
- (NSInteger)addButtonWithTitle:(NSString*)title action:(void(^)(void))action;
- (NSInteger)addCancelButtonWithTitle:(NSString*)title action:(void(^)(void))action;
- (NSInteger)addDestructiveButtonWithTitle:(NSString*)title action:(void(^)(void))action;
- (void)showFromWhatever;
@property (nonatomic, copy) void (^finalAction)(void);
@property (nonatomic, copy) void (^cancelAction)(void);
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/NSMutableSet+ETRUtils.h
|
//
// NSMutableSet+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSMutableSet (ETRUtils)
- (void)etr_safeAdd:(id)object;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/UIView+ETRUtils.h
|
<reponame>Vadim-Yelagin/ETRUtils<gh_stars>0
//
// UIView+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UIView (ETRUtils)
- (UIView*)etr_findFirstResponder;
@property (nonatomic) CGFloat parallaxAmplitude;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/UITableViewCell+ETRUtils.h
|
//
// UITableViewCell+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UITableViewCell (ETRUtils)
@property (nonatomic, copy) UIColor* selectionColor;
@property (nonatomic, copy) UIColor* backgroundViewColor;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/NSBlockOperation+ETRUtils.h
|
<filename>Pod/Classes/ETRCategories/NSBlockOperation+ETRUtils.h
//
// NSBlockOperation+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSBlockOperation (ETRUtils)
+ (id)etr_blockOperationWithBlock2:(void (^)(NSBlockOperation* operation))block;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/NSError+ETRUtils.h
|
<filename>Example/Pods/Headers/Public/ETRUtils/NSError+ETRUtils.h
//
// NSError+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSError (ETRUtils)
- (BOOL)etr_isCancelledError;
- (NSString *)etr_description;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRStringDecorator.h
|
<gh_stars>0
//
// ETRStringDecorator.h
//
// Created by <NAME> on 17/06/14.
// Copyright (c) 2014 EastBanc Technologies. All rights reserved.
//
@import UIKit;
@interface ETRStringDecorator : NSObject <UITextFieldDelegate, UITextViewDelegate>
@property (nonatomic, copy) NSArray* formats;
@property (nonatomic, copy) NSString* dataCharacters;
@property (nonatomic, copy) NSString* placeholderCharacter;
- (instancetype)initWithFormats:(NSArray *)formats NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithDateStringTemplate:(NSString *)stringTemplate;
- (NSString*)decorateString:(NSString*)dataString;
- (NSString*)distillString:(NSString*)decoratedString;
- (NSRange)convertRange:(NSRange)range
fromDecoratedString:(NSString*)decoratedString;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/NSString+ETRUtils.h
|
//
// NSString+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSString (ETRUtils)
- (NSInteger)etr_numberOfWords;
- (NSString*)etr_stringBySafeAppend:(NSString*)string;
- (NSDecimalNumber*)etr_decimalNumberValue;
- (NSString*)etr_stringByRemovingNonBMPCharacters;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/ETRAlertView.h
|
<reponame>Vadim-Yelagin/ETRUtils
//
// ETRAlertView.h
//
// Created by <NAME> on 9/18/13.
// Copyright (c) 2013 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface ETRAlertView : UIAlertView
+ (instancetype)alertView;
- (NSInteger)addButtonWithTitle:(NSString*)title action:(void(^)(void))action;
- (NSInteger)addCancelButtonWithTitle:(NSString*)title action:(void(^)(void))action;
@property (nonatomic, copy) void (^finalAction)(void);
@property (nonatomic, copy) void (^cancelAction)(void);
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/NSFetchedResultsController+ETRUtils.h
|
//
// NSFetchedResultsController+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import CoreData;
@import UIKit;
@interface NSFetchedResultsController (ETRUtils) <UIDataSourceModelAssociation>
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/UICollectionView+ETRUtils.h
|
<filename>Pod/Classes/ETRCategories/UICollectionView+ETRUtils.h
//
// UICollectionView+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UICollectionView (ETRUtils)
- (void)etr_deselectAllItemsAnimated:(BOOL)animated;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/NSArray+ETRUtils.h
|
<filename>Example/Pods/Headers/Public/ETRUtils/NSArray+ETRUtils.h
//
// NSArray+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSArray (ETRUtils)
- (NSInteger)etr_minimumUsingComparator:(NSComparator)cmptr;
- (NSArray *)etr_map:(id(^)(id obj))block;
- (NSArray *)etr_filter:(BOOL(^)(id obj))block;
- (NSArray *)etr_flatMap:(NSArray *(^)(id obj))block;
- (NSArray *)etr_flatten;
- (NSArray *)etr_take:(NSInteger)count;
- (NSDictionary *)etr_collateBy:(id<NSCopying>(^)(id obj))block;
- (NSDictionary *)etr_collateByKeyPath:(NSString *)keyPath;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/UIRefreshControl+ETRUtils.h
|
//
// UIRefreshControl+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UIRefreshControl (ETRUtils)
@property (nonatomic, readwrite, getter = isRefreshing) BOOL refreshing;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/NSTimer+ETRUtils.h
|
<filename>Pod/Classes/ETRCategories/NSTimer+ETRUtils.h
//
// NSTimer+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import Foundation;
@interface NSTimer (ETRUtils)
- (instancetype)initWithFireDate:(NSDate *)date
interval:(NSTimeInterval)interval
block:(void(^)(NSTimer *timer))block
repeats:(BOOL)repeats;
@end
|
Vadim-Yelagin/ETRUtils
|
Pod/Classes/ETRCategories/UIViewController+ETRUtils.h
|
//
// UIViewController+ETRUtils.h
//
// Created by <NAME> on 15/10/14.
// Copyright (c) 2014 EastBanc Technologies Russia. All rights reserved.
//
@import UIKit;
@interface UIViewController (ETRUtils)
- (void)etr_alertError:(NSError*)error;
@end
|
Vadim-Yelagin/ETRUtils
|
Example/Pods/Headers/Public/ETRUtils/ETRUtils.h
|
<filename>Example/Pods/Headers/Public/ETRUtils/ETRUtils.h
//
// ETRUtils.h
//
// Created by <NAME> on 28/10/13.
// Copyright (c) 2013 EastBanc Technologies Russia. All rights reserved.
//
#import "NSArray+ETRUtils.h"
#import "NSBlockOperation+ETRUtils.h"
#import "NSError+ETRUtils.h"
#import "NSFetchedResultsController+ETRUtils.h"
#import "NSMutableArray+ETRUtils.h"
#import "NSMutableDictionary+ETRUtils.h"
#import "NSMutableSet+ETRUtils.h"
#import "NSMutableString+ETRUtils.h"
#import "NSNumber+ETRUtils.h"
#import "NSString+ETRUtils.h"
#import "NSTimer+ETRUtils.h"
#import "UIActivityIndicatorView+ETRUtils.h"
#import "UICollectionView+ETRUtils.h"
#import "UIColor+ETRUtils.h"
#import "UIImage+ETRUtils.h"
#import "UIRefreshControl+ETRUtils.h"
#import "UITableView+ETRUtils.h"
#import "UITableViewCell+ETRUtils.h"
#import "UIView+ETRUtils.h"
#import "UIViewController+ETRUtils.h"
extern NSString* NSStringFromNSIndexPath(NSIndexPath* indexPath);
extern NSIndexPath* NSIndexPathFromNSString(NSString* string);
@interface ETRUtils : NSObject
+ (BOOL)isOS7;
+ (BOOL)isIpad;
+ (NSURL *)applicationCachesDirectory;
+ (NSURL *)applicationDocumentsDirectory;
+ (NSString*)russianPluralForQuantity:(NSInteger)quantity
single:(NSString*)singleForm
few:(NSString*)fewForm
many:(NSString*)manyForm;
+ (NSString*)russianQuantityWithPlural:(NSInteger)quantity
single:(NSString*)singleForm
few:(NSString*)fewForm
many:(NSString*)manyForm;
@end
|
leozz37/sputnik
|
sputnik/vector_utils.h
|
<filename>sputnik/vector_utils.h<gh_stars>100-1000
// Copyright 2020 The Sputnik Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_SPUTNIK_VECTOR_UTILS_H_
#define THIRD_PARTY_SPUTNIK_VECTOR_UTILS_H_
/**
* @file @brief Utilities for working with CUDA vector data types.
*/
#include "sputnik/cuda_utils.h"
#include "sputnik/type_utils.h"
namespace sputnik {
/**
* @brief Functor for computing FMAs & MULs on mixes of vector and scalar
* data types.
*/
template <typename Value>
struct VectorCompute {
typedef typename TypeUtils<Value>::Accumulator Accumulator;
static __device__ __forceinline__ void FMA(float x1, Value x2,
Accumulator *out);
// Complementary index type to our load type.
typedef typename Value2Index<Value>::Index Index;
static __device__ __forceinline__ void Mul(int, Index x2, Index *out);
static __device__ __forceinline__ void Dot(Value x1, Value x2,
Accumulator *out);
};
template <>
struct VectorCompute<float> {
static __device__ __forceinline__ void FMA(float x1, float x2, float *out) {
out[0] += x1 * x2;
}
static __device__ __forceinline__ void Mul(int x1, int x2, int *out) {
out[0] = x1 * x2;
}
static __device__ __forceinline__ void Dot(float x1, float x2, float *out) {
out[0] += x1 * x2;
}
};
template <>
struct VectorCompute<float2> {
static __device__ __forceinline__ void FMA(float x1, float2 x2, float2 *out) {
out[0].x += x1 * x2.x;
out[0].y += x1 * x2.y;
}
static __device__ __forceinline__ void Mul(int x1, int2 x2, int2 *out) {
out[0].x = x1 * x2.x;
out[0].y = x1 * x2.y;
}
static __device__ __forceinline__ void Dot(float2 x1, float2 x2, float *out) {
out[0] += x1.x * x2.x;
out[0] += x1.y * x2.y;
}
};
template <>
struct VectorCompute<float4> {
static __device__ __forceinline__ void FMA(float x1, float4 x2, float4 *out) {
out[0].x += x1 * x2.x;
out[0].y += x1 * x2.y;
out[0].z += x1 * x2.z;
out[0].w += x1 * x2.w;
}
static __device__ __forceinline__ void Mul(int x1, int4 x2, int4 *out) {
out[0].x = x1 * x2.x;
out[0].y = x1 * x2.y;
out[0].z = x1 * x2.z;
out[0].w = x1 * x2.w;
}
static __device__ __forceinline__ void Dot(float4 x1, float4 x2, float *out) {
out[0] += x1.x * x2.x;
out[0] += x1.y * x2.y;
out[0] += x1.z * x2.z;
out[0] += x1.w * x2.w;
}
};
template <>
struct VectorCompute<half2> {
static __device__ __forceinline__ void FMA(float x1, half2 x2, float2 *out) {
float2 x2_f2 = __half22float2(x2);
VectorCompute<float2>::FMA(x1, x2_f2, out);
}
static __device__ __forceinline__ void Mul(int x1, short2 x2, short2 *out) {
out[0].x = static_cast<short>(x1 * x2.x);
out[0].y = static_cast<short>(x1 * x2.y);
}
};
template <>
struct VectorCompute<half4> {
static __device__ __forceinline__ void FMA(float x1, half4 x2, float4 *out) {
float2 x2x_f2 = __half22float2(x2.x);
float2 x2y_f2 = __half22float2(x2.y);
float4 x2_f4 = make_float4(x2x_f2.x, x2x_f2.y, x2y_f2.x, x2y_f2.y);
VectorCompute<float4>::FMA(x1, x2_f4, out);
}
static __device__ __forceinline__ void Mul(int x1, short4 x2, short4 *out) {
VectorCompute<half2>::Mul(x1, x2.x, &out[0].x);
VectorCompute<half2>::Mul(x1, x2.y, &out[0].y);
}
};
template <>
struct VectorCompute<half8> {
static __device__ __forceinline__ void FMA(float x1, half8 x2, float4 *out) {
half4 x2x_h4;
x2x_h4.x = x2.x;
x2x_h4.y = x2.y;
VectorCompute<half4>::FMA(x1, x2x_h4, out);
half4 x2y_h4;
x2y_h4.x = x2.z;
x2y_h4.y = x2.w;
VectorCompute<half4>::FMA(x1, x2y_h4, out + 1);
}
static __device__ __forceinline__ void Mul(int x1, short8 x2, short8 *out) {
VectorCompute<half2>::Mul(x1, x2.x, &out[0].x);
VectorCompute<half2>::Mul(x1, x2.y, &out[0].y);
VectorCompute<half2>::Mul(x1, x2.z, &out[0].z);
VectorCompute<half2>::Mul(x1, x2.w, &out[0].w);
}
};
} // namespace sputnik
#endif // THIRD_PARTY_SPUTNIK_VECTOR_UTILS_H_
|
HubESI/SYC2
|
2020/TP/BELGOUMRI_SIAHMED_1CS1/include/functions.h
|
<filename>2020/TP/BELGOUMRI_SIAHMED_1CS1/include/functions.h
#ifndef __FUNCTIONS__H__
#define __FUNCTIONS__H__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <getopt.h>
#include <sys/stat.h>
#include <fnmatch.h>
#include <dirent.h>
#define PATH_LEN 1024
void printHelp(int help);
void printVersion(int version);
void printDirectory(
char* path,
char* pattern,
int date,
int modification,
int protection,
int size,
int type,
int depth
);
void printFileType(int type, struct stat filestat);
void printHeader(int date, int modification, int protection, int size, int type);
void printLastUsed(int date, struct stat filestat);
void printLastModified(int modification, struct stat filestat);
void printProtection(int protection, struct stat filestat);
void printSize(int size, struct stat filestat);
const char *unit(off_t bytes);
off_t reducedSize(off_t bytes);
#endif //__FUNCTIONS__H__
|
HubESI/SYC2
|
2020/TP/BELGOUMRI_SIAHMED_1CS1/source/functions.c
|
#include"include/functions.h"
void printHelp(int help)
{
if (help)
{
printf("This is search version 1.0.0\n");
// Synopsis
printf("Synopsis:\n");
printf("\tsearch [directory][-a][-d][-h][-m][-n][-p][-s][-t][-v] pattern\n");
// Description
printf("Description:\n");
printf("\tPrints out a list of all files matching `pattern` within `directory`. If `directory` \n\tis unspecified, the working directory is the default.\n");
// Options
printf("Options:\n");
printf("\t-a\t\t\tSame as -d -s -t -p\n");
printf("\t-d\t\t\tPrint last access date.\n");
printf("\t-h\t\t\tPrint this help text and exit.\n");
printf("\t-m\t\t\tPrint last modification date.\n");
printf("\t-n (n integer)\t\tSearch in directory and all its children of depth =< n (infinite by default).\n");
printf("\t-p\t\t\tPrint protection.\n");
printf("\t-s\t\t\tPrint size.\n");
printf("\t-t\t\t\tPrint type.\n");
printf("\t-v\t\t\tPrint program version and exit.\n");
exit(EXIT_SUCCESS);
}
}
void printVersion(int version)
{
if (version)
{
printf("This is search version 1.0\n");
exit(EXIT_SUCCESS);
}
}
void printDirectory(
char* path,
char* pattern,
int date,
int modification,
int protection,
int size,
int type,
int depth
)
{
// Exit if depth reached
if (depth == -1)
return;
DIR* directory = NULL; // To contain the opened directory
struct dirent* file = NULL; // To contain the files in directory
struct stat filestat; // To contain file status
directory = opendir(path);
// Open path in directory and exit if failed
if (directory == NULL)
{
fprintf(stderr, "Error while trying to open %s\n", path);
exit(EXIT_FAILURE);
}
//Readdir until NULL
while ((file = readdir(directory)) != NULL)
{
// Ignore ., .. and all hidden files
if (file->d_name[0] == '.')
continue;
char buf[PATH_LEN]; // To contain the full path to file
strcpy(buf, path); // Add path
if (strcmp(buf, "/")) // If path is /, no need to add a '/'
strcat(buf, "/");
strcat(buf, file -> d_name); // Add file name
if (stat(buf, &filestat)) // Get status in filestat and exit if stat failed
{
fprintf(stderr, "Error: Failed to get status for %s\n", buf);
exit(EXIT_FAILURE);
}
// If file is a directory, apply the search to it recursively
if (S_ISDIR(filestat.st_mode))
printDirectory(
buf,
pattern,
date,
modification,
protection,
size,
type,
depth - 1
);
// Test for pattern match and print if successful
if (!fnmatch(pattern, file -> d_name, 0))
{
printFileType(type, filestat);
printProtection(protection, filestat);
printSize(size, filestat);
printLastUsed(date, filestat);
printLastModified(modification, filestat);
printf("%s\n", buf);
}
}
// Close directory and exit if failed
if (closedir(directory) == -1)
{
fprintf(stderr, "Error while trying to close %s\n", path);
exit(EXIT_FAILURE);
}
}
void printFileType(int type, struct stat filestat)
{
if (type)
{
if (S_ISDIR(filestat.st_mode))
printf("%-12s","directory");
else if (S_ISREG(filestat.st_mode))
printf("%-12s","regular");
else if (S_ISCHR(filestat.st_mode))
printf("%-12s","character");
else if (S_ISBLK(filestat.st_mode))
printf("%-12s","block");
else if (S_ISFIFO(filestat.st_mode))
printf("%-12s","fifo");
else if (S_ISLNK(filestat.st_mode))
printf("%-12s","link");
else if (S_ISSOCK(filestat.st_mode))
printf("%-12s","socket");
else
{
fprintf(stderr, "Error: Unknown file type %d\n", filestat.st_mode);
exit(EXIT_FAILURE);
}
}
}
void printHeader(int date, int modification, int protection, int size, int type)
{
if (type)
printf("%-12s", "Type");
if (protection)
printf("%-12s", "Protection");
if (size)
printf("%-10s", "Size");
if(date)
printf("%-14s", "Last used");
if (modification)
printf("%-15s", "Last modified");
printf("%s\n", "Name");
}
void printLastUsed(int date, struct stat filestat)
{
if (date)
printf(
"%02d/%02d/%04d%-4s",
localtime(&filestat.st_atim.tv_sec)->tm_mday,
(localtime(&filestat.st_atim.tv_sec)->tm_mon + 1),
(localtime(&filestat.st_atim.tv_sec)->tm_year + 1900),
" "
);
}
void printLastModified(int modification, struct stat filestat)
{
if (modification)
printf(
"%02d/%02d/%04d%-5s",
localtime(&filestat.st_atim.tv_sec)->tm_mday,
(localtime(&filestat.st_atim.tv_sec)->tm_mon + 1),
(localtime(&filestat.st_atim.tv_sec)->tm_year + 1900),
" "
);
}
void printProtection(int protection, struct stat filestat)
{
if (protection)
printf(
"%o%-9s",
(filestat.st_mode & 0777), // Mode & mask
" "
);
}
void printSize(int size, struct stat filestat)
{
if (size)
printf(
"%4ld %-3s%-2s",
reducedSize(filestat.st_size),
unit(filestat.st_size),
" "
);
}
const char *unit(off_t bytes)
{
if (bytes < 10000)
return "";
else if (bytes < 10000000)
return "Kbs";
else if (bytes < 10000000000)
return "Mbs";
else
return "Gbs";
}
off_t reducedSize(off_t bytes)
{
if (bytes < 10000)
return bytes;
else if (bytes < 10000000)
return bytes / 1000;
else if (bytes < 10000000000)
return bytes / 1000000;
else
return bytes / 1000000000;
}
|
HubESI/SYC2
|
2020/TP/BELGOUMRI_SIAHMED_1CS1/source/main.c
|
<filename>2020/TP/BELGOUMRI_SIAHMED_1CS1/source/main.c
#include "include/functions.h"
int main(int argc, char *argv[])
{
int c; //To contain getopt() return
static int fall, fdate, fhelp, fmodification, fprotection, fsize, ftype, fversion; //flag returns
int depth = __INT_MAX__;
char path[PATH_LEN];
char pattern[PATH_LEN];
char regargv[2][PATH_LEN];
int regargc = 0;
// Loop to parse args
for (int i = 1; i < argc; i++)
{
//Handle flags
if (argv[i][0] == '-')
{
// depth
if (isdigit(argv[i][1]))
{
depth = atoi(argv[i] + 1);
}
// Flags
else
{
switch (argv[i][1])
{
case 'a':
fall = 1;
break;
case 'v':
fversion = 1;
break;
case 'h':
fhelp = 1;
break;
case 'd':
fdate = 1;
break;
case 'm':
fmodification = 1;
break;
case 'p':
fprotection = 1;
break;
case 's':
fsize = 1;
break;
case 't':
ftype = 1;
break;
default:
fprintf(stderr, "Error: Unknown option: %s\n", argv[i] + 1);
break;
}
}
}
// Regular arguments
else
{
strcpy(regargv[regargc], argv[i]);
regargc++;
}
}
printHelp(fhelp);
printVersion(fversion);
// Test for missing arguments
if (regargc == 0)
fprintf(stderr, "Error: Missing mandatory argument: filename");
// Test for missing path
else if (regargc == 1)
{
strcpy(path, "."); //Default path is .
strcpy(pattern, regargv[0]);
}
else if (regargc == 2)
{
strcpy(path, regargv[0]);
strcpy(pattern, regargv[1]);
}
else
fprintf(stderr, "Error: Too many arguments\n");
// Handle -a
if (fall)
fdate = fsize = ftype = fprotection = 1;
printHeader(fdate, fmodification, fprotection, fsize, ftype);
printDirectory(path, pattern, fdate, fmodification, fprotection, fsize, ftype, depth);
return EXIT_SUCCESS;
}
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/RedBullet.h
|
#pragma once
#include "bulletobject.h"
class RedBullet :
public BulletObject
{
public:
RedBullet(void);
void setExplode();
void reset();
~RedBullet(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/Global.h
|
#define GRAVITY 3
#define GROUND 440
extern int mapPosition;
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/GroundEnemy.h
|
#pragma once
#include "BulletObject.h"
#include "EnemyObject.h"
class GroundEnemy :
public EnemyObject
{
public:
GroundEnemy(void);
int prevX;
int prevY;
int health;
void checkCollisionWithBlock(GraphicsObject *block);
void onHit(BulletObject *b);
void move();
~GroundEnemy(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/GraphicsObject.h
|
<reponame>Kashif-S/Megaman
#pragma once
class GraphicsObject
{
public:
GraphicsObject(int i, int m, int posx, int posy, int w = 50, int h = 50);
int ID;
int maskID;
int width;
int height;
int hitHeight;
int hitWidth;
int y;
int x;
int picX;
int picY;
int endcell;
int currcell;
int startcell;
bool loopcell;
void loadImage();
HDC image;
HDC mask;
void draw(HDC offscreenDC);
void animate();
bool hitTest(GraphicsObject object);
~GraphicsObject(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/BackgroundObject.h
|
#pragma once
#include "GraphicsObject.h"
class BackgroundObject : public GraphicsObject
{
public:
BackgroundObject(int i, int posX, int posY, int h, int w, double ss);
void draw(HDC offscreenDC);
double scrollSpeed;
~BackgroundObject(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/MegamanObject.h
|
#pragma once
#include "WeaponsObject.h"
#include "BulletObject.h"
#define MOVERIGHT 1
#define MOVELEFT 2
#define STANDRIGHT 3
#define STANDLEFT 4
#define JUMPRIGHT 5
#define JUMPLEFT 6
#define SHOOTRIGHT 7
#define SHOOTLEFT 8
class MegamanObject : public WeaponsObject
{
public:
MegamanObject(void);
int prevX;
int prevY;
int Yspeed;
int Xspeed;
int state;
int tothealth;
int curhealth;
void move();
void setMoveRight();
void setMoveleft();
void setStandRight();
void setStandleft();
void setJumpRight();
void setJumpleft();
void setShootRight();
void setShootLeft();
bool isJumping();
void onHit(BulletObject *b);
void checkCollsionWithBlock(GraphicsObject *block);
~MegamanObject(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/FlyingEnemy.h
|
<reponame>Kashif-S/Megaman<filename>MegaManKS/Kashif_MegaMan/FlyingEnemy.h<gh_stars>0
#pragma once
#include "enemyobject.h"
#include "MegamanObject.h"
class FlyingEnemy :
public EnemyObject
{
public:
FlyingEnemy(MegamanObject *m, int cx, int cy);
MegamanObject *megaman;
int radius;
int angle;
int centerx;
int centery;
virtual void move();
virtual void onHit(BulletObject *b);
virtual void checkCollisionWithBlock(GraphicsObject *block);
virtual void fire();
~FlyingEnemy(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/LifeBar.h
|
<filename>MegaManKS/Kashif_MegaMan/LifeBar.h
#pragma once
#include"GraphicsObject.h"
#include"MegamanObject.h"
#include"Resource.h"
class LifeBar
{
public:
LifeBar(MegamanObject *m);
MegamanObject *megaman;
void draw(HDC screen);
~LifeBar(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/EnemyObject.h
|
#pragma once
#include "weaponsobject.h"
class EnemyObject :
public WeaponsObject
{
public:
EnemyObject(int i, int m, int posx, int posy) : WeaponsObject(i, m, posx, posy)
{
xspeed = 0;
yspeed = 0;
isDead = false;
}
int xspeed;
int yspeed;
bool isDead;
virtual void move() = 0;
virtual void onHit(BulletObject *b) = 0;
virtual void checkCollisionWithBlock(GraphicsObject *block) = 0;
~EnemyObject(void)
{
}
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/BulletObject.h
|
<gh_stars>0
#pragma once
#include "graphicsobject.h"
#include "resource.h"
class BulletObject :
public GraphicsObject
{
public:
BulletObject(int i, int m);
int xspeed;
int yspeed;
int distanceTravelled;
int maxDistance;
bool fired;
bool exploding;
void move();
virtual void setExplode();
virtual void reset();
int damage;
~BulletObject(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/BlueBullet.h
|
#pragma once
#include "bulletobject.h"
class BlueBullet :
public BulletObject
{
public:
BlueBullet(void);
void setExplode();
void reset();
~BlueBullet(void);
};
|
Kashif-S/Megaman
|
MegaManKS/Kashif_MegaMan/WeaponsObject.h
|
#pragma once
#include "graphicsobject.h"
#include "BulletObject.h"
class WeaponsObject :
public GraphicsObject
{
public:
WeaponsObject(int i, int m, int posX, int posY);
int numBullets;
BulletObject *bullets[50];
void fireBullet(int x, int y, int xspeed, int yspeed);
void drawBullets(HDC offscreenDC);
void moveBullets();
void checkBulletCollsionWithBlock(GraphicsObject *block);
void checkBulletCollisionWithObject(WeaponsObject *object);
virtual void onHit(BulletObject *b){};
~WeaponsObject(void);
};
|
RyukieSama/RYText
|
RYText/RYTextView/RYTextView.h
|
//
// RYTextView.h
// Ryuk
//
// Created by RongqingWang on 2017/5/12.
// Copyright © 2017年 RyukieSama. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RYTextView : UITextView
@end
|
RyukieSama/RYText
|
RYText/RYLabel/RYLabel.h
|
<reponame>RyukieSama/RYText<gh_stars>1-10
//
// RYLabel.h
// Ryuk
//
// Created by RongqingWang on 2017/5/12.
// Copyright © 2017年 RyukieSama. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreText/CoreText.h>
#import "RYTextUnit.h"
typedef void(^textClickHandler)(RYTextUnit *unit);
@interface RYLabel : UILabel
@property (nonatomic, copy) textClickHandler textClick;
@end
|
RyukieSama/RYText
|
RYText/RYTextUnit.h
|
//
// RYTextUnit.h
// Ryuk
//
// Created by RongqingWang on 2017/5/12.
// Copyright © 2017年 RyukieSama. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, RYTextUnitType) {
RYTextUnitTypeURL = 11,
RYTextUnitTypeAt = 12,
RYTextUnitTypeEmoji = 13,
RYTextUnitTypeSharp = 14
};
@interface RYTextUnit : NSObject
@property (nonatomic, copy) NSString *content;
@property (nonatomic, assign) NSRange range;
@property (nonatomic, assign) RYTextUnitType type;
@end
|
danielScLima/LeftistHeap
|
leftistheapnode.h
|
<reponame>danielScLima/LeftistHeap
#ifndef LEFTISTHEAPNODE_H
#define LEFTISTHEAPNODE_H
#include <iostream>
/*!
* \brief The LeftistHeapNode struct
*/
struct LeftistHeapNode
{
/*!
* \brief LeftistHeapNode
* \param data
* \param father
*/
LeftistHeapNode(int data, LeftistHeapNode* father);
/*!
* \brief calculateStoreAndReturnNPL
* \return
*/
int calculateStoreAndReturnNPL();
/*!
* \brief search
* \param data
* \return
*/
bool search(int data);
int data = 0;
int npl = 0; //null path length
struct LeftistHeapNode* left = nullptr;
struct LeftistHeapNode* right = nullptr;
struct LeftistHeapNode* father = nullptr;
};
#endif // LEFTISTHEAPNODE_H
|
danielScLima/LeftistHeap
|
leftistheap.h
|
<gh_stars>0
#ifndef LEFTIST_HEAP_H
#define LEFTIST_HEAP_H
#include <iostream>
#include <vector>
#include "leftistheapnode.h"
/*!
* \brief The LeftistHeapDS class
*/
class LeftistHeapDS
{
public:
/*!
* \brief LeftistHeapDS
*/
LeftistHeapDS();
~LeftistHeapDS();
/*!
* \brief getRoot
* \return
*/
LeftistHeapNode* getRoot();
/*!
* \brief insert
* \param data
*/
void insert(int data);
/*!
* \brief removeMin
* \return
*/
struct LeftistHeapNode* removeMin();
/*!
* \brief search
* \param data
* \return
*/
bool search(int data);
/*!
* \brief gitDotFileMode1
* \return
*/
const std::string gitDotFileMode1();
/*!
* \brief gitDotFileMode2
* \return
*/
const std::string gitDotFileMode2();
/*!
* \brief preOrder
* \return
*/
const std::string preOrder();
/*!
* \brief inOrder
* \return
*/
const std::string inOrder();
/*!
* \brief posOrder
* \return
*/
const std::string posOrder();
/*!
* \brief InLevelOrder
* \return
*/
const std::string InLevelOrder();
/*!
* \brief merge
* \param heapOne
* \param heapTwo
*/
void merge(LeftistHeapNode *heapOne, LeftistHeapNode *heapTwo);
/*!
* \brief setRoot
* \param node
*/
void setRoot(LeftistHeapNode *node);
private:
struct LeftistHeapNode* root = nullptr;
/*!
* \brief exibirSubArvore1
* \param n
* \param content
* \param count
*/
void exibirSubArvore1(LeftistHeapNode *n, std::string &content, int& count);
/*!
* \brief exibirSubArvore2
* \param father
* \param isLeftSon
* \param n
* \param content
* \param count
*/
void exibirSubArvore2(LeftistHeapNode *father, bool isLeftSon, LeftistHeapNode *n, std::string &content, int &count);
/*!
* \brief preOrder
* \param node
* \param content
*/
void preOrder(LeftistHeapNode *node, std::string &content);
/*!
* \brief inOrder
* \param node
* \param content
*/
void inOrder(LeftistHeapNode *node, std::string &content);
/*!
* \brief posOrder
* \param node
* \param content
*/
void posOrder(LeftistHeapNode *node, std::string &content);
/*!
* \brief checkAndCorrectIfNeeded
* \param node
*/
void checkAndCorrectIfNeeded(LeftistHeapNode *node);
/*!
* \brief updateNPLToAllHeap
*/
void updateNPLToAllHeap();
/*!
* \brief merge
* \param heapOne
* \param heapTwo
* \param stack
*/
void merge(LeftistHeapNode* heapOne, LeftistHeapNode* heapTwo, std::vector<LeftistHeapNode*>& stack);
/*!
* \brief insertInHeapOfMerge
* \param node
* \param stack
*/
void insertInHeapOfMerge(LeftistHeapNode* node, std::vector<LeftistHeapNode*> &stack);
/*!
* \brief dealockSubTree
* \param node
*/
void dealockSubTree(LeftistHeapNode *node);
};
#endif // LEFTIST_HEAP_H
|
urbanze/esp32-eth
|
eth.h
|
<gh_stars>1-10
#ifndef eth_H
#define eth_H
#include <esp_err.h>
#include <esp_log.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_event.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include <lwip/netdb.h>
#include <string.h>
#include "esp_eth.h"
#include "driver/gpio.h"
/**
@file eth.h
@author <NAME>
Class to use Ethernet
MIT License
Copyright (c) 2020 <NAME>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
class ETH
{
private:
const char tag[4] = "ETH";
static int8_t _status;
static char _ip[16];
static void eth_event(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
static void ip_event(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
public:
int8_t init(uint8_t wait);
int8_t status();
char *get_ip();
};
#endif
|
astrangeguy/libx11-debian-mirror
|
src/StNColor.c
|
<reponame>astrangeguy/libx11-debian-mirror
/*
Copyright 1986, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include "Xcmsint.h"
int
XStoreNamedColor(
register Display *dpy,
Colormap cmap,
_Xconst char *name, /* STRING8 */
unsigned long pixel, /* CARD32 */
int flags) /* DoRed, DoGreen, DoBlue */
{
unsigned int nbytes;
register xStoreNamedColorReq *req;
XcmsCCC ccc;
XcmsColor cmsColor_exact;
XColor scr_def;
#ifdef XCMS
/*
* Let's Attempt to use Xcms approach to Parse Color
*/
if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) {
if (_XcmsResolveColorString(ccc, &name, &cmsColor_exact,
XcmsRGBFormat) >= XcmsSuccess) {
_XcmsRGB_to_XColor(&cmsColor_exact, &scr_def, 1);
scr_def.pixel = pixel;
scr_def.flags = flags;
return XStoreColor(dpy, cmap, &scr_def);
}
/*
* Otherwise we failed; or name was changed with yet another
* name. Thus pass name to the X Server.
*/
}
#endif
/*
* The Xcms and i18n methods failed, so lets pass it to the server
* for parsing.
*/
LockDisplay(dpy);
GetReq(StoreNamedColor, req);
req->cmap = cmap;
req->flags = flags;
req->pixel = pixel;
req->nbytes = nbytes = strlen(name);
req->length += (nbytes + 3) >> 2; /* round up to multiple of 4 */
Data(dpy, name, (long)nbytes);
UnlockDisplay(dpy);
SyncHandle();
return 0;
}
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBExtDev.c
|
<reponame>astrangeguy/libx11-debian-mirror<filename>src/xkb/XKBExtDev.c<gh_stars>0
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#define NEED_MAP_READERS
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include "XKBlibint.h"
#include <X11/extensions/XI.h>
/***====================================================================***/
extern void
XkbNoteDeviceChanges( XkbDeviceChangesPtr old,
XkbExtensionDeviceNotifyEvent * new,
unsigned int wanted)
{
if ((!old)||(!new)||(!wanted)||((new->reason&wanted)==0))
return;
if ((wanted&new->reason)&XkbXI_ButtonActionsMask) {
if (old->changed&XkbXI_ButtonActionsMask) {
int first,last,newLast;
if (new->first_btn<old->first_btn)
first= new->first_btn;
else first= old->first_btn;
last= old->first_btn+old->num_btns-1;
newLast= new->first_btn+new->num_btns-1;
if (newLast>last)
last= newLast;
old->first_btn= first;
old->num_btns= (last-first)+1;
}
else {
old->changed|= XkbXI_ButtonActionsMask;
old->first_btn= new->first_btn;
old->num_btns= new->num_btns;
}
}
if ((wanted&new->reason)&XkbXI_IndicatorsMask) {
XkbDeviceLedChangesPtr this;
if (old->changed&XkbXI_IndicatorsMask) {
XkbDeviceLedChangesPtr found;
found= NULL;
for (this= &old->leds;this&&(!found);this=this->next) {
if ((this->led_class==new->led_class)&&
(this->led_id==new->led_id)) {
found= this;
}
}
if (!found) {
found= _XkbTypedCalloc(1,XkbDeviceLedChangesRec);
if (!found)
return;
found->next= old->leds.next;
found->led_class= new->led_class;
found->led_id= new->led_id;
old->leds.next= found;
}
if ((wanted&new->reason)&XkbXI_IndicatorNamesMask)
found->defined= new->leds_defined;
}
else {
old->changed|= ((wanted&new->reason)&XkbXI_IndicatorsMask);
old->leds.led_class= new->led_class;
old->leds.led_id= new->led_id;
old->leds.defined= new->leds_defined;
if (old->leds.next) {
XkbDeviceLedChangesPtr next;
for (this=old->leds.next;this;this=next) {
next= this->next;
_XkbFree(this);
}
old->leds.next= NULL;
}
}
}
return;
}
/***====================================================================***/
static Status
_XkbReadDeviceLedInfo( XkbReadBufferPtr buf,
unsigned present,
XkbDeviceInfoPtr devi)
{
register unsigned i,bit;
XkbDeviceLedInfoPtr devli;
xkbDeviceLedsWireDesc * wireli;
wireli= _XkbGetTypedRdBufPtr(buf,1,xkbDeviceLedsWireDesc);
if (!wireli)
return BadLength;
devli= XkbAddDeviceLedInfo(devi,wireli->ledClass,wireli->ledID);
if (!devli)
return BadAlloc;
devli->phys_indicators= wireli->physIndicators;
if (present&XkbXI_IndicatorStateMask)
devli->state= wireli->state;
if (present&XkbXI_IndicatorNamesMask) {
devli->names_present= wireli->namesPresent;
if (devli->names_present) {
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (wireli->namesPresent&bit) {
if (!_XkbCopyFromReadBuffer(buf,(char *)&devli->names[i],4))
return BadLength;
}
}
}
}
if (present&XkbXI_IndicatorMapsMask) {
devli->maps_present= wireli->mapsPresent;
if (devli->maps_present) {
XkbIndicatorMapPtr im;
xkbIndicatorMapWireDesc * wireim;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (wireli->mapsPresent&bit) {
wireim= _XkbGetTypedRdBufPtr(buf,1,xkbIndicatorMapWireDesc);
if (!wireim)
return BadAlloc;
im= &devli->maps[i];
im->flags= wireim->flags;
im->which_groups= wireim->whichGroups;
im->groups= wireim->groups;
im->which_mods= wireim->whichMods;
im->mods.mask= wireim->mods;
im->mods.real_mods= wireim->realMods;
im->mods.vmods= wireim->virtualMods;
im->ctrls= wireim->ctrls;
}
}
}
}
return Success;
}
static Status
_XkbReadGetDeviceInfoReply( Display * dpy,
xkbGetDeviceInfoReply * rep,
XkbDeviceInfoPtr devi)
{
XkbReadBufferRec buf;
XkbAction * act;
int tmp;
if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
return BadAlloc;
if ((rep->totalBtns>0)&&(rep->totalBtns!=devi->num_btns)) {
tmp= XkbResizeDeviceButtonActions(devi,rep->totalBtns);
if (tmp!=Success)
return tmp;
}
if (rep->nBtnsWanted>0) {
act= &devi->btn_acts[rep->firstBtnWanted];
bzero((char *)act,(rep->nBtnsWanted*sizeof(XkbAction)));
}
if (devi->name!=NULL)
_XkbFree(devi->name);
if (!_XkbGetReadBufferCountedString(&buf,&devi->name))
goto BAILOUT;
if (rep->nBtnsRtrn>0) {
int size;
act= &devi->btn_acts[rep->firstBtnRtrn];
size= rep->nBtnsRtrn*SIZEOF(xkbActionWireDesc);
if (!_XkbCopyFromReadBuffer(&buf,(char *)act,size))
goto BAILOUT;
}
if (rep->nDeviceLedFBs>0) {
register int i;
for (i=0;i<rep->nDeviceLedFBs;i++) {
if ((tmp= _XkbReadDeviceLedInfo(&buf,rep->present,devi))!=Success)
return tmp;
}
}
tmp= _XkbFreeReadBuffer(&buf);
if (tmp)
fprintf(stderr,"GetDeviceInfo! Bad length (%d extra bytes)\n",tmp);
if (tmp || buf.error)
return BadLength;
return Success;
BAILOUT:
_XkbFreeReadBuffer(&buf);
return BadLength;
}
XkbDeviceInfoPtr
XkbGetDeviceInfo( Display * dpy,
unsigned which,
unsigned deviceSpec,
unsigned class,
unsigned id)
{
register xkbGetDeviceInfoReq * req;
xkbGetDeviceInfoReply rep;
Status status;
XkbDeviceInfoPtr devi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return NULL;
LockDisplay(dpy);
GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = deviceSpec;
req->wanted= which;
req->allBtns= ((which&XkbXI_ButtonActionsMask)!=0);
req->firstBtn= req->nBtns= 0;
req->ledClass= class;
req->ledID= id;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return NULL;
}
devi= XkbAllocDeviceInfo(rep.deviceID,rep.totalBtns,rep.nDeviceLedFBs);
if (devi) {
devi->supported= rep.supported;
devi->unsupported= rep.unsupported;
devi->type= rep.devType;
devi->has_own_state= rep.hasOwnState;
devi->dflt_kbd_fb = rep.dfltKbdFB;
devi->dflt_led_fb = rep.dfltLedFB;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
if (status!=Success) {
XkbFreeDeviceInfo(devi,XkbXI_AllDeviceFeaturesMask,True);
devi= NULL;
}
}
UnlockDisplay(dpy);
SyncHandle();
return devi;
}
Status
XkbGetDeviceInfoChanges( Display * dpy,
XkbDeviceInfoPtr devi,
XkbDeviceChangesPtr changes)
{
register xkbGetDeviceInfoReq * req;
xkbGetDeviceInfoReply rep;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadMatch;
if ((changes->changed&XkbXI_AllDeviceFeaturesMask)==0)
return Success;
changes->changed&= ~XkbXI_AllDeviceFeaturesMask;
status= Success;
LockDisplay(dpy);
while ((changes->changed)&&(status==Success)) {
GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = devi->device_spec;
req->wanted= changes->changed;
req->allBtns= False;
if (changes->changed&XkbXI_ButtonActionsMask) {
req->firstBtn= changes->first_btn;
req->nBtns= changes->num_btns;
changes->changed&= ~XkbXI_ButtonActionsMask;
}
else req->firstBtn= req->nBtns= 0;
if (changes->changed&XkbXI_IndicatorsMask) {
req->ledClass= changes->leds.led_class;
req->ledID= changes->leds.led_id;
if (changes->leds.next==NULL)
changes->changed&= ~XkbXI_IndicatorsMask;
else {
XkbDeviceLedChangesPtr next;
next= changes->leds.next;
changes->leds= *next;
_XkbFree(next);
}
}
else {
req->ledClass= XkbDfltXIClass;
req->ledID= XkbDfltXIId;
}
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
status= BadLength;
break;
}
devi->supported|= rep.supported;
devi->unsupported|= rep.unsupported;
devi->type= rep.devType;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
}
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetDeviceButtonActions( Display * dpy,
XkbDeviceInfoPtr devi,
Bool all,
unsigned int first,
unsigned int num)
{
register xkbGetDeviceInfoReq * req;
xkbGetDeviceInfoReply rep;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadMatch;
if (!devi)
return BadValue;
LockDisplay(dpy);
GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = devi->device_spec;
req->wanted= XkbXI_ButtonActionsMask;
req->allBtns= all;
req->firstBtn= first;
req->nBtns= num;
req->ledClass= XkbDfltXIClass;
req->ledID= XkbDfltXIId;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return BadLength;
}
devi->type= rep.devType;
devi->supported= rep.supported;
devi->unsupported= rep.unsupported;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetDeviceLedInfo( Display * dpy,
XkbDeviceInfoPtr devi,
unsigned int ledClass,
unsigned int ledId,
unsigned int which)
{
register xkbGetDeviceInfoReq * req;
xkbGetDeviceInfoReply rep;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadMatch;
if (((which&XkbXI_IndicatorsMask)==0)||(which&(~XkbXI_IndicatorsMask)))
return BadMatch;
if (!devi)
return BadValue;
LockDisplay(dpy);
GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = devi->device_spec;
req->wanted= which;
req->allBtns= False;
req->firstBtn= req->nBtns= 0;
req->ledClass= ledClass;
req->ledID= ledId;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return BadLength;
}
devi->type= rep.devType;
devi->supported= rep.supported;
devi->unsupported= rep.unsupported;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
/***====================================================================***/
typedef struct _LedInfoStuff {
Bool used;
XkbDeviceLedInfoPtr devli;
} LedInfoStuff;
typedef struct _SetLedStuff {
unsigned wanted;
int num_info;
int dflt_class;
LedInfoStuff * dflt_kbd_fb;
LedInfoStuff * dflt_led_fb;
LedInfoStuff * info;
} SetLedStuff;
static void
_InitLedStuff(SetLedStuff *stuff,unsigned wanted,XkbDeviceInfoPtr devi)
{
int i;
register XkbDeviceLedInfoPtr devli;
bzero(stuff,sizeof(SetLedStuff));
stuff->wanted= wanted;
stuff->dflt_class= XkbXINone;
if ((devi->num_leds<1)||((wanted&XkbXI_IndicatorsMask)==0))
return;
stuff->info= _XkbTypedCalloc(devi->num_leds,LedInfoStuff);
if (!stuff->info)
return;
stuff->num_info= devi->num_leds;
for (devli=&devi->leds[0],i=0;i<devi->num_leds;i++,devli++) {
stuff->info[i].devli= devli;
if (devli->led_class==KbdFeedbackClass) {
stuff->dflt_class= KbdFeedbackClass;
if (stuff->dflt_kbd_fb==NULL)
stuff->dflt_kbd_fb= &stuff->info[i];
}
else if (devli->led_class==LedFeedbackClass) {
if (stuff->dflt_class==XkbXINone)
stuff->dflt_class= LedFeedbackClass;
if (stuff->dflt_led_fb==NULL)
stuff->dflt_led_fb= &stuff->info[i];
}
}
return;
}
static void
_FreeLedStuff(SetLedStuff *stuff)
{
if ((stuff->num_info>0)&&(stuff->info!=NULL))
_XkbFree(stuff->info);
bzero(stuff,sizeof(SetLedStuff));
return;
}
static int
_XkbSizeLedInfo(unsigned changed,XkbDeviceLedInfoPtr devli)
{
register int i,size;
register unsigned bit,namesNeeded,mapsNeeded;
size= SIZEOF(xkbDeviceLedsWireDesc);
namesNeeded= mapsNeeded= 0;
if (changed&XkbXI_IndicatorNamesMask)
namesNeeded= devli->names_present;
if (changed&XkbXI_IndicatorMapsMask)
mapsNeeded= devli->maps_present;
if ((namesNeeded)||(mapsNeeded)) {
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (namesNeeded&bit)
size+= 4; /* atoms are 4 bytes on the wire */
if (mapsNeeded&bit)
size+= SIZEOF(xkbIndicatorMapWireDesc);
}
}
return size;
}
static Bool
_SizeMatches( SetLedStuff * stuff,
XkbDeviceLedChangesPtr changes,
int * sz_rtrn,
int * nleds_rtrn)
{
int i,nMatch,class,id;
LedInfoStuff * linfo;
Bool match;
nMatch= 0;
class= changes->led_class;
id= changes->led_id;
if (class==XkbDfltXIClass)
class= stuff->dflt_class;
for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
XkbDeviceLedInfoPtr devli;
LedInfoStuff * dflt;
devli= linfo->devli;
match= ((class==devli->led_class)||(class==XkbAllXIClasses));
if (devli->led_class==KbdFeedbackClass) dflt= stuff->dflt_kbd_fb;
else dflt= stuff->dflt_led_fb;
match = (match && (id == devli->led_id)) ||
(id == XkbAllXIIds) ||
((id == XkbDfltXIId) &&
(linfo == dflt));
if (match) {
if (!linfo->used) {
*sz_rtrn+= _XkbSizeLedInfo(stuff->wanted,devli);
*nleds_rtrn+= 1;
linfo->used= True;
if ((class!=XkbAllXIClasses)&&(id!=XkbAllXIIds))
return True;
}
nMatch++;
linfo->used= True;
}
}
return (nMatch>0);
}
/***====================================================================***/
static Status
_XkbSetDeviceInfoSize( XkbDeviceInfoPtr devi,
XkbDeviceChangesPtr changes,
SetLedStuff * stuff,
int * sz_rtrn,
int * num_leds_rtrn)
{
*sz_rtrn= 0;
if ((changes->changed&XkbXI_ButtonActionsMask)&&(changes->num_btns>0)) {
if (!XkbXI_LegalDevBtn(devi,(changes->first_btn+changes->num_btns-1)))
return BadMatch;
*sz_rtrn+= changes->num_btns*SIZEOF(xkbActionWireDesc);
}
else {
changes->changed&= ~XkbXI_ButtonActionsMask;
changes->first_btn= changes->num_btns= 0;
}
if ((changes->changed&XkbXI_IndicatorsMask)&&
XkbLegalXILedClass(changes->leds.led_class)) {
XkbDeviceLedChangesPtr leds;
for (leds=&changes->leds;leds!=NULL;leds= leds->next) {
if (!_SizeMatches(stuff,leds,sz_rtrn,num_leds_rtrn))
return BadMatch;
}
}
else {
changes->changed&= ~XkbXI_IndicatorsMask;
*num_leds_rtrn= 0;
}
return Success;
}
static char *
_XkbWriteLedInfo(char *wire,unsigned changed,XkbDeviceLedInfoPtr devli)
{
register int i;
register unsigned bit,namesNeeded,mapsNeeded;
xkbDeviceLedsWireDesc * lwire;
namesNeeded= mapsNeeded= 0;
if (changed&XkbXI_IndicatorNamesMask)
namesNeeded= devli->names_present;
if (changed&XkbXI_IndicatorMapsMask)
mapsNeeded= devli->maps_present;
lwire= (xkbDeviceLedsWireDesc *)wire;
lwire->ledClass= devli->led_class;
lwire->ledID= devli->led_id;
lwire->namesPresent= namesNeeded;
lwire->mapsPresent= mapsNeeded;
lwire->physIndicators= devli->phys_indicators;
lwire->state= devli->state;
wire= (char *)&lwire[1];
if (namesNeeded) {
CARD32 *awire;
awire= (CARD32 *)wire;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (namesNeeded&bit) {
*awire= (CARD32)devli->names[i];
awire++;
}
}
wire= (char *)awire;
}
if (mapsNeeded) {
xkbIndicatorMapWireDesc *mwire;
mwire= (xkbIndicatorMapWireDesc *)wire;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (mapsNeeded&bit) {
XkbIndicatorMapPtr map;
map= &devli->maps[i];
mwire->flags= map->flags;
mwire->whichGroups= map->which_groups;
mwire->groups= map->groups;
mwire->whichMods= map->which_mods;
mwire->mods= map->mods.mask;
mwire->realMods= map->mods.real_mods;
mwire->virtualMods= map->mods.vmods;
mwire->ctrls= map->ctrls;
mwire++;
}
}
wire= (char *)mwire;
}
return wire;
}
static int
_XkbWriteSetDeviceInfo( char * wire,
XkbDeviceChangesPtr changes,
SetLedStuff * stuff,
XkbDeviceInfoPtr devi)
{
char *start;
start= wire;
if (changes->changed&XkbXI_ButtonActionsMask) {
int size;
size= changes->num_btns*SIZEOF(xkbActionWireDesc);
memcpy(wire,(char *)&devi->btn_acts[changes->first_btn],size);
wire+= size;
}
if (changes->changed&XkbXI_IndicatorsMask) {
register int i;
register LedInfoStuff *linfo;
for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
if (linfo->used) {
register char *new_wire;
new_wire= _XkbWriteLedInfo(wire,stuff->wanted,linfo->devli);
if (!new_wire)
return wire-start;
wire= new_wire;
}
}
}
return wire-start;
}
Bool
XkbSetDeviceInfo( Display * dpy,
unsigned which,
XkbDeviceInfoPtr devi)
{
register xkbSetDeviceInfoReq *req;
Status ok = 0;
int size,nLeds;
XkbInfoPtr xkbi;
XkbDeviceChangesRec changes;
SetLedStuff lstuff;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
if ((!devi) || (which&(~XkbXI_AllDeviceFeaturesMask)) ||
((which&XkbXI_ButtonActionsMask)&&(!XkbXI_DevHasBtnActs(devi)))||
((which&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
return False;
bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
changes.changed= which;
changes.first_btn= 0;
changes.num_btns= devi->num_btns;
changes.leds.led_class= XkbAllXIClasses;
changes.leds.led_id= XkbAllXIIds;
changes.leds.defined= 0;
size= nLeds= 0;
_InitLedStuff(&lstuff,changes.changed,devi);
if (_XkbSetDeviceInfoSize(devi,&changes,&lstuff,&size,&nLeds)!=Success)
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbSetDeviceInfo, req);
req->length+= size/4;
req->reqType= xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDeviceInfo;
req->deviceSpec= devi->device_spec;
req->firstBtn= changes.first_btn;
req->nBtns= changes.num_btns;
req->change= changes.changed;
req->nDeviceLedFBs= nLeds;
if (size>0) {
char * wire;
BufAlloc(char *,wire,size);
ok= (wire!=NULL)&&
(_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
}
UnlockDisplay(dpy);
SyncHandle();
_FreeLedStuff(&lstuff);
/* 12/11/95 (ef) -- XXX!! should clear changes here */
return ok;
}
Bool
XkbChangeDeviceInfo( Display * dpy,
XkbDeviceInfoPtr devi,
XkbDeviceChangesPtr changes)
{
register xkbSetDeviceInfoReq *req;
Status ok = 0;
int size,nLeds;
XkbInfoPtr xkbi;
SetLedStuff lstuff;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
if ((!devi) || (changes->changed&(~XkbXI_AllDeviceFeaturesMask)) ||
((changes->changed&XkbXI_ButtonActionsMask)&&
(!XkbXI_DevHasBtnActs(devi)))||
((changes->changed&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
return False;
size= nLeds= 0;
_InitLedStuff(&lstuff,changes->changed,devi);
if (_XkbSetDeviceInfoSize(devi,changes,&lstuff,&size,&nLeds)!=Success)
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbSetDeviceInfo, req);
req->length+= size/4;
req->reqType= xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDeviceInfo;
req->deviceSpec= devi->device_spec;
req->firstBtn= changes->first_btn;
req->nBtns= changes->num_btns;
req->change= changes->changed;
req->nDeviceLedFBs= nLeds;
if (size>0) {
char * wire;
BufAlloc(char *,wire,size);
ok= (wire!=NULL)&&
(_XkbWriteSetDeviceInfo(wire,changes,&lstuff,devi)==size);
}
UnlockDisplay(dpy);
SyncHandle();
_FreeLedStuff(&lstuff);
/* 12/11/95 (ef) -- XXX!! should clear changes here */
return ok;
}
Bool
XkbSetDeviceLedInfo( Display * dpy,
XkbDeviceInfoPtr devi,
unsigned ledClass,
unsigned ledID,
unsigned which)
{
return False;
}
Bool
XkbSetDeviceButtonActions( Display * dpy,
XkbDeviceInfoPtr devi,
unsigned int first,
unsigned int nBtns)
{
register xkbSetDeviceInfoReq *req;
Status ok = 0;
int size,nLeds;
XkbInfoPtr xkbi;
XkbDeviceChangesRec changes;
SetLedStuff lstuff;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
if ((!devi)||(!XkbXI_DevHasBtnActs(devi))||(first+nBtns>devi->num_btns))
return False;
if (nBtns==0)
return True;
bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
changes.changed= XkbXI_ButtonActionsMask;
changes.first_btn= first;
changes.num_btns= nBtns;
changes.leds.led_class= XkbXINone;
changes.leds.led_id= XkbXINone;
changes.leds.defined= 0;
size= nLeds= 0;
if (_XkbSetDeviceInfoSize(devi,&changes,NULL,&size,&nLeds)!=Success)
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbSetDeviceInfo, req);
req->length+= size/4;
req->reqType= xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDeviceInfo;
req->deviceSpec= devi->device_spec;
req->firstBtn= changes.first_btn;
req->nBtns= changes.num_btns;
req->change= changes.changed;
req->nDeviceLedFBs= nLeds;
if (size>0) {
char * wire;
BufAlloc(char *,wire,size);
ok= (wire!=NULL)&&
(_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
}
UnlockDisplay(dpy);
SyncHandle();
return ok;
}
|
astrangeguy/libx11-debian-mirror
|
src/GetRGBCMap.c
|
<filename>src/GetRGBCMap.c
/*
Copyright 1987, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include "Xatomtype.h"
#include <X11/Xatom.h>
Status XGetRGBColormaps (
Display *dpy,
Window w,
XStandardColormap **stdcmap, /* RETURN */
int *count, /* RETURN */
Atom property) /* XA_RGB_BEST_MAP, etc. */
{
register int i; /* iterator variable */
xPropStandardColormap *data = NULL; /* data read in from prop */
Atom actual_type; /* how the prop was actually stored */
int actual_format; /* ditto */
unsigned long leftover; /* how much was left over */
unsigned long nitems; /* number of 32bits read */
int ncmaps; /* number of structs this makes */
Bool old_style = False; /* if was too short */
VisualID def_visual = None; /* visual to use if prop too short */
XStandardColormap *cmaps; /* return value */
if (XGetWindowProperty (dpy, w, property, 0L, 1000000L, False,
XA_RGB_COLOR_MAP, &actual_type, &actual_format,
&nitems, &leftover, (unsigned char **)&data)
!= Success)
return False;
/* if wrong type or format, or too small for us, then punt */
if ((actual_type != XA_RGB_COLOR_MAP) || (actual_format != 32) ||
(nitems < OldNumPropStandardColormapElements)) {
if (data) Xfree ((char *) data);
return False;
}
/*
* See how many properties were found; if pre-ICCCM then assume
* default visual and a kill id of 1.
*/
if (nitems < NumPropStandardColormapElements) {
ncmaps = 1;
old_style = True;
if (nitems < (NumPropStandardColormapElements - 1)) {
Screen *sp = _XScreenOfWindow (dpy, w);
if (!sp) {
if (data) Xfree ((char *) data);
return False;
}
def_visual = sp->root_visual->visualid;
}
} else {
/*
* make sure we have an integral number of colormaps
*/
ncmaps = (nitems / NumPropStandardColormapElements);
if ((((unsigned long) ncmaps) * NumPropStandardColormapElements) !=
nitems) {
if (data) Xfree ((char *) data);
return False;
}
}
/*
* allocate array
*/
cmaps = (XStandardColormap *) Xmalloc (ncmaps *
sizeof (XStandardColormap));
if (!cmaps) {
if (data) Xfree ((char *) data);
return False;
}
/*
* and fill it in, handling compatibility with pre-ICCCM short stdcmaps
*/
{
register XStandardColormap *map;
register xPropStandardColormap *prop;
for (i = ncmaps, map = cmaps, prop = data; i > 0; i--, map++, prop++) {
map->colormap = prop->colormap;
map->red_max = prop->red_max;
map->red_mult = prop->red_mult;
map->green_max = prop->green_max;
map->green_mult = prop->green_mult;
map->blue_max = prop->blue_max;
map->blue_mult = prop->blue_mult;
map->base_pixel = prop->base_pixel;
map->visualid = (def_visual ? def_visual : prop->visualid);
map->killid = (old_style ? None : prop->killid);
}
}
Xfree ((char *) data);
*stdcmap = cmaps;
*count = ncmaps;
return True;
}
|
astrangeguy/libx11-debian-mirror
|
src/xlibi18n/XimTrInt.h
|
/*
* Copyright 1992 Oracle and/or its affiliates. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/******************************************************************
Copyright 1993, 1994 by FUJITSU LIMITED
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation, and that the name of FUJITSU LIMITED
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission.
FUJITSU LIMITED makes no representations about the suitability of
this software for any purpose.
It is provided "as is" without express or implied warranty.
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Author: <NAME> (<EMAIL>) Sun Microsystems, Inc.
<NAME> FUJITSU LIMITED
<EMAIL>
******************************************************************/
#ifndef _XIMTRINT_H
#define _XIMTRINT_H
#include "Ximint.h"
typedef struct {
const char *transportname;
Bool (*config)(
Xim,
char *
);
} TransportSW;
extern TransportSW _XimTransportRec[];
/*
* Global symbols
*/
extern Bool _XimXConf(
Xim im,
char *address
);
#if defined(TCPCONN) || defined(UNIXCONN) || defined(DNETCONN) || defined(STREAMSCONN)
extern Bool _XimTransConf(
Xim im,
char *address
);
#endif
#endif /* _XIMTRINT_H */
|
astrangeguy/libx11-debian-mirror
|
src/xlibi18n/imKStoUCS.c
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include "Ximint.h"
static unsigned short const keysym_to_unicode_1a1_1ff[] = {
0x0104, 0x02d8, 0x0141, 0x0000, 0x013d, 0x015a, 0x0000, /* 0x01a0-0x01a7 */
0x0000, 0x0160, 0x015e, 0x0164, 0x0179, 0x0000, 0x017d, 0x017b, /* 0x01a8-0x01af */
0x0000, 0x0105, 0x02db, 0x0142, 0x0000, 0x013e, 0x015b, 0x02c7, /* 0x01b0-0x01b7 */
0x0000, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, /* 0x01b8-0x01bf */
0x0154, 0x0000, 0x0000, 0x0102, 0x0000, 0x0139, 0x0106, 0x0000, /* 0x01c0-0x01c7 */
0x010c, 0x0000, 0x0118, 0x0000, 0x011a, 0x0000, 0x0000, 0x010e, /* 0x01c8-0x01cf */
0x0110, 0x0143, 0x0147, 0x0000, 0x0000, 0x0150, 0x0000, 0x0000, /* 0x01d0-0x01d7 */
0x0158, 0x016e, 0x0000, 0x0170, 0x0000, 0x0000, 0x0162, 0x0000, /* 0x01d8-0x01df */
0x0155, 0x0000, 0x0000, 0x0103, 0x0000, 0x013a, 0x0107, 0x0000, /* 0x01e0-0x01e7 */
0x010d, 0x0000, 0x0119, 0x0000, 0x011b, 0x0000, 0x0000, 0x010f, /* 0x01e8-0x01ef */
0x0111, 0x0144, 0x0148, 0x0000, 0x0000, 0x0151, 0x0000, 0x0000, /* 0x01f0-0x01f7 */
0x0159, 0x016f, 0x0000, 0x0171, 0x0000, 0x0000, 0x0163, 0x02d9 /* 0x01f8-0x01ff */
};
static unsigned short const keysym_to_unicode_2a1_2fe[] = {
0x0126, 0x0000, 0x0000, 0x0000, 0x0000, 0x0124, 0x0000, /* 0x02a0-0x02a7 */
0x0000, 0x0130, 0x0000, 0x011e, 0x0134, 0x0000, 0x0000, 0x0000, /* 0x02a8-0x02af */
0x0000, 0x0127, 0x0000, 0x0000, 0x0000, 0x0000, 0x0125, 0x0000, /* 0x02b0-0x02b7 */
0x0000, 0x0131, 0x0000, 0x011f, 0x0135, 0x0000, 0x0000, 0x0000, /* 0x02b8-0x02bf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010a, 0x0108, 0x0000, /* 0x02c0-0x02c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x02c8-0x02cf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0120, 0x0000, 0x0000, /* 0x02d0-0x02d7 */
0x011c, 0x0000, 0x0000, 0x0000, 0x0000, 0x016c, 0x015c, 0x0000, /* 0x02d8-0x02df */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010b, 0x0109, 0x0000, /* 0x02e0-0x02e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x02e8-0x02ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0121, 0x0000, 0x0000, /* 0x02f0-0x02f7 */
0x011d, 0x0000, 0x0000, 0x0000, 0x0000, 0x016d, 0x015d /* 0x02f8-0x02ff */
};
static unsigned short const keysym_to_unicode_3a2_3fe[] = {
0x0138, 0x0156, 0x0000, 0x0128, 0x013b, 0x0000, /* 0x03a0-0x03a7 */
0x0000, 0x0000, 0x0112, 0x0122, 0x0166, 0x0000, 0x0000, 0x0000, /* 0x03a8-0x03af */
0x0000, 0x0000, 0x0000, 0x0157, 0x0000, 0x0129, 0x013c, 0x0000, /* 0x03b0-0x03b7 */
0x0000, 0x0000, 0x0113, 0x0123, 0x0167, 0x014a, 0x0000, 0x014b, /* 0x03b8-0x03bf */
0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012e, /* 0x03c0-0x03c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0116, 0x0000, 0x0000, 0x012a, /* 0x03c8-0x03cf */
0x0000, 0x0145, 0x014c, 0x0136, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x03d0-0x03d7 */
0x0000, 0x0172, 0x0000, 0x0000, 0x0000, 0x0168, 0x016a, 0x0000, /* 0x03d8-0x03df */
0x0101, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012f, /* 0x03e0-0x03e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0117, 0x0000, 0x0000, 0x012b, /* 0x03e8-0x03ef */
0x0000, 0x0146, 0x014d, 0x0137, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x03f0-0x03f7 */
0x0000, 0x0173, 0x0000, 0x0000, 0x0000, 0x0169, 0x016b /* 0x03f8-0x03ff */
};
static unsigned short const keysym_to_unicode_4a1_4df[] = {
0x3002, 0x3008, 0x3009, 0x3001, 0x30fb, 0x30f2, 0x30a1, /* 0x04a0-0x04a7 */
0x30a3, 0x30a5, 0x30a7, 0x30a9, 0x30e3, 0x30e5, 0x30e7, 0x30c3, /* 0x04a8-0x04af */
0x30fc, 0x30a2, 0x30a4, 0x30a6, 0x30a8, 0x30aa, 0x30ab, 0x30ad, /* 0x04b0-0x04b7 */
0x30af, 0x30b1, 0x30b3, 0x30b5, 0x30b7, 0x30b9, 0x30bb, 0x30bd, /* 0x04b8-0x04bf */
0x30bf, 0x30c1, 0x30c4, 0x30c6, 0x30c8, 0x30ca, 0x30cb, 0x30cc, /* 0x04c0-0x04c7 */
0x30cd, 0x30ce, 0x30cf, 0x30d2, 0x30d5, 0x30d8, 0x30db, 0x30de, /* 0x04c8-0x04cf */
0x30df, 0x30e0, 0x30e1, 0x30e2, 0x30e4, 0x30e6, 0x30e8, 0x30e9, /* 0x04d0-0x04d7 */
0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ef, 0x30f3, 0x309b, 0x309c /* 0x04d8-0x04df */
};
static unsigned short const keysym_to_unicode_590_5fe[] = {
0x06f0, 0x06f1, 0x06f2, 0x06f3, 0x06f4, 0x06f5, 0x06f6, 0x06f7, /* 0x0590-0x0597 */
0x06f8, 0x06f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x0598-0x059f */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x066a, 0x0670, 0x0679, /* 0x05a0-0x05a7 */
0x067e, 0x0686, 0x0688, 0x0691, 0x060c, 0x0000, 0x06d4, 0x0000, /* 0x05ac-0x05af */
0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, /* 0x05b0-0x05b7 */
0x0668, 0x0669, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f, /* 0x05b8-0x05bf */
0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, /* 0x05c0-0x05c7 */
0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, /* 0x05c8-0x05cf */
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, /* 0x05d0-0x05d7 */
0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x05d8-0x05df */
0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, /* 0x05e0-0x05e7 */
0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f, /* 0x05e8-0x05ef */
0x0650, 0x0651, 0x0652, 0x0653, 0x0654, 0x0655, 0x0698, 0x06a4, /* 0x05f0-0x05f7 */
0x06a9, 0x06af, 0x06ba, 0x06be, 0x06cc, 0x06d2, 0x06c1 /* 0x05f8-0x05fe */
};
static unsigned short keysym_to_unicode_680_6ff[] = {
0x0492, 0x0496, 0x049a, 0x049c, 0x04a2, 0x04ae, 0x04b0, 0x04b2, /* 0x0680-0x0687 */
0x04b6, 0x04b8, 0x04ba, 0x0000, 0x04d8, 0x04e2, 0x04e8, 0x04ee, /* 0x0688-0x068f */
0x0493, 0x0497, 0x049b, 0x049d, 0x04a3, 0x04af, 0x04b1, 0x04b3, /* 0x0690-0x0697 */
0x04b7, 0x04b9, 0x04bb, 0x0000, 0x04d9, 0x04e3, 0x04e9, 0x04ef, /* 0x0698-0x069f */
0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, /* 0x06a0-0x06a7 */
0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0491, 0x045e, 0x045f, /* 0x06a8-0x06af */
0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, /* 0x06b0-0x06b7 */
0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0490, 0x040e, 0x040f, /* 0x06b8-0x06bf */
0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, /* 0x06c0-0x06c7 */
0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, /* 0x06c8-0x06cf */
0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, /* 0x06d0-0x06d7 */
0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, /* 0x06d8-0x06df */
0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, /* 0x06e0-0x06e7 */
0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, /* 0x06e8-0x06ef */
0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, /* 0x06f0-0x06f7 */
0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a /* 0x06f8-0x06ff */
};
static unsigned short const keysym_to_unicode_7a1_7f9[] = {
0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c, /* 0x07a0-0x07a7 */
0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015, /* 0x07a8-0x07af */
0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, /* 0x07b0-0x07b7 */
0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x07b8-0x07bf */
0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, /* 0x07c0-0x07c7 */
0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, /* 0x07c8-0x07cf */
0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7, /* 0x07d0-0x07d7 */
0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x07d8-0x07df */
0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, /* 0x07e0-0x07e7 */
0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, /* 0x07e8-0x07ef */
0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, /* 0x07f0-0x07f7 */
0x03c8, 0x03c9 /* 0x07f8-0x07ff */
};
static unsigned short const keysym_to_unicode_8a4_8fe[] = {
0x2320, 0x2321, 0x0000, 0x231c, /* 0x08a0-0x08a7 */
0x231d, 0x231e, 0x231f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08a8-0x08af */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08b0-0x08b7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222b, /* 0x08b8-0x08bf */
0x2234, 0x0000, 0x221e, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000, /* 0x08c0-0x08c7 */
0x2245, 0x2246, 0x0000, 0x0000, 0x0000, 0x0000, 0x21d2, 0x0000, /* 0x08c8-0x08cf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221a, 0x0000, /* 0x08d0-0x08d7 */
0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222a, 0x2227, 0x2228, /* 0x08d8-0x08df */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08e0-0x08e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202, /* 0x08e8-0x08ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000, /* 0x08f0-0x08f7 */
0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193 /* 0x08f8-0x08ff */
};
static unsigned short const keysym_to_unicode_9df_9f8[] = {
0x2422, /* 0x09d8-0x09df */
0x2666, 0x25a6, 0x2409, 0x240c, 0x240d, 0x240a, 0x0000, 0x0000, /* 0x09e0-0x09e7 */
0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x2500, /* 0x09e8-0x09ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */
0x2502 /* 0x09f8-0x09ff */
};
static unsigned short const keysym_to_unicode_aa1_afe[] = {
0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, /* 0x0aa0-0x0aa7 */
0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025, /* 0x0aa8-0x0aaf */
0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a, /* 0x0ab0-0x0ab7 */
0x2105, 0x0000, 0x0000, 0x2012, 0x2039, 0x2024, 0x203a, 0x0000, /* 0x0ab8-0x0abf */
0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000, /* 0x0ac0-0x0ac7 */
0x0000, 0x2122, 0x2120, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25ad, /* 0x0ac8-0x0acf */
0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000, 0x2032, 0x2033, /* 0x0ad0-0x0ad7 */
0x0000, 0x271d, 0x0000, 0x220e, 0x25c2, 0x2023, 0x25cf, 0x25ac, /* 0x0ad8-0x0adf */
0x25e6, 0x25ab, 0x25ae, 0x25b5, 0x25bf, 0x2606, 0x2022, 0x25aa, /* 0x0ae0-0x0ae7 */
0x25b4, 0x25be, 0x261a, 0x261b, 0x2663, 0x2666, 0x2665, 0x0000, /* 0x0ae8-0x0aef */
0x2720, 0x2020, 0x2021, 0x2713, 0x2612, 0x266f, 0x266d, 0x2642, /* 0x0af0-0x0af7 */
0x2640, 0x2121, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e /* 0x0af8-0x0aff */
};
/* none of the APL keysyms match the Unicode characters */
static unsigned short const keysym_to_unicode_cdf_cfa[] = {
0x2017, /* 0x0cd8-0x0cdf */
0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, /* 0x0ce0-0x0ce7 */
0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, /* 0x0ce8-0x0cef */
0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, /* 0x0cf0-0x0cf7 */
0x05e8, 0x05e9, 0x05ea /* 0x0cf8-0x0cff */
};
static unsigned short const keysym_to_unicode_da1_df9[] = {
0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, /* 0x0da0-0x0da7 */
0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, /* 0x0da8-0x0daf */
0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, /* 0x0db0-0x0db7 */
0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, /* 0x0db8-0x0dbf */
0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, /* 0x0dc0-0x0dc7 */
0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, /* 0x0dc8-0x0dcf */
0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, /* 0x0dd0-0x0dd7 */
0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0e3e, 0x0e3f, /* 0x0dd8-0x0ddf */
0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, /* 0x0de0-0x0de7 */
0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0000, 0x0000, /* 0x0de8-0x0def */
0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, /* 0x0df0-0x0df7 */
0x0e58, 0x0e59 /* 0x0df8-0x0dff */
};
static unsigned short const keysym_to_unicode_ea0_eff[] = {
0x0000, 0x1101, 0x1101, 0x11aa, 0x1102, 0x11ac, 0x11ad, 0x1103, /* 0x0ea0-0x0ea7 */
0x1104, 0x1105, 0x11b0, 0x11b1, 0x11b2, 0x11b3, 0x11b4, 0x11b5, /* 0x0ea8-0x0eaf */
0x11b6, 0x1106, 0x1107, 0x1108, 0x11b9, 0x1109, 0x110a, 0x110b, /* 0x0eb0-0x0eb7 */
0x110c, 0x110d, 0x110e, 0x110f, 0x1110, 0x1111, 0x1112, 0x1161, /* 0x0eb8-0x0ebf */
0x1162, 0x1163, 0x1164, 0x1165, 0x1166, 0x1167, 0x1168, 0x1169, /* 0x0ec0-0x0ec7 */
0x116a, 0x116b, 0x116c, 0x116d, 0x116e, 0x116f, 0x1170, 0x1171, /* 0x0ec8-0x0ecf */
0x1172, 0x1173, 0x1174, 0x1175, 0x11a8, 0x11a9, 0x11aa, 0x11ab, /* 0x0ed0-0x0ed7 */
0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3, /* 0x0ed8-0x0edf */
0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb, /* 0x0ee0-0x0ee7 */
0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x0000, /* 0x0ee8-0x0eef */
0x0000, 0x0000, 0x1140, 0x0000, 0x0000, 0x1159, 0x119e, 0x0000, /* 0x0ef0-0x0ef7 */
0x11eb, 0x0000, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9, /* 0x0ef8-0x0eff */
};
static unsigned short keysym_to_unicode_12a1_12fe[] = {
0x1e02, 0x1e03, 0x0000, 0x0000, 0x0000, 0x1e0a, 0x0000, /* 0x12a0-0x12a7 */
0x1e80, 0x0000, 0x1e82, 0x1e0b, 0x1ef2, 0x0000, 0x0000, 0x0000, /* 0x12a8-0x12af */
0x1e1e, 0x1e1f, 0x0000, 0x0000, 0x1e40, 0x1e41, 0x0000, 0x1e56, /* 0x12b0-0x12b7 */
0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, /* 0x12b8-0x12bf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12c0-0x12c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12c8-0x12cf */
0x0174, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1e6a, /* 0x12d0-0x12d7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0176, 0x0000, /* 0x12d8-0x12df */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12e0-0x12e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12e8-0x12ef */
0x0175, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1e6b, /* 0x12f0-0x12f7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0177 /* 0x12f0-0x12ff */
};
static unsigned short const keysym_to_unicode_13bc_13be[] = {
0x0152, 0x0153, 0x0178 /* 0x13b8-0x13bf */
};
static unsigned short keysym_to_unicode_14a1_14ff[] = {
0x2741, 0x00a7, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab, /* 0x14a0-0x14a7 */
0x2014, 0x002e, 0x055d, 0x002c, 0x2013, 0x058a, 0x2026, 0x055c, /* 0x14a8-0x14af */
0x055b, 0x055e, 0x0531, 0x0561, 0x0532, 0x0562, 0x0533, 0x0563, /* 0x14b0-0x14b7 */
0x0534, 0x0564, 0x0535, 0x0565, 0x0536, 0x0566, 0x0537, 0x0567, /* 0x14b8-0x14bf */
0x0538, 0x0568, 0x0539, 0x0569, 0x053a, 0x056a, 0x053b, 0x056b, /* 0x14c0-0x14c7 */
0x053c, 0x056c, 0x053d, 0x056d, 0x053e, 0x056e, 0x053f, 0x056f, /* 0x14c8-0x14cf */
0x0540, 0x0570, 0x0541, 0x0571, 0x0542, 0x0572, 0x0543, 0x0573, /* 0x14d0-0x14d7 */
0x0544, 0x0574, 0x0545, 0x0575, 0x0546, 0x0576, 0x0547, 0x0577, /* 0x14d8-0x14df */
0x0548, 0x0578, 0x0549, 0x0579, 0x054a, 0x057a, 0x054b, 0x057b, /* 0x14e0-0x14e7 */
0x054c, 0x057c, 0x054d, 0x057d, 0x054e, 0x057e, 0x054f, 0x057f, /* 0x14e8-0x14ef */
0x0550, 0x0580, 0x0551, 0x0581, 0x0552, 0x0582, 0x0553, 0x0583, /* 0x14f0-0x14f7 */
0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x2019, 0x0027, /* 0x14f8-0x14ff */
};
static unsigned short keysym_to_unicode_15d0_15f6[] = {
0x10d0, 0x10d1, 0x10d2, 0x10d3, 0x10d4, 0x10d5, 0x10d6, 0x10d7, /* 0x15d0-0x15d7 */
0x10d8, 0x10d9, 0x10da, 0x10db, 0x10dc, 0x10dd, 0x10de, 0x10df, /* 0x15d8-0x15df */
0x10e0, 0x10e1, 0x10e2, 0x10e3, 0x10e4, 0x10e5, 0x10e6, 0x10e7, /* 0x15e0-0x15e7 */
0x10e8, 0x10e9, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x10ee, 0x10ef, /* 0x15e8-0x15ef */
0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6 /* 0x15f0-0x15f7 */
};
static unsigned short keysym_to_unicode_16a0_16f6[] = {
0x0000, 0x0000, 0xf0a2, 0x1e8a, 0x0000, 0xf0a5, 0x012c, 0xf0a7, /* 0x16a0-0x16a7 */
0xf0a8, 0x01b5, 0x01e6, 0x0000, 0x0000, 0x0000, 0x0000, 0x019f, /* 0x16a8-0x16af */
0x0000, 0x0000, 0xf0b2, 0x1e8b, 0x01d1, 0xf0b5, 0x012d, 0xf0b7, /* 0x16b0-0x16b7 */
0xf0b8, 0x01b6, 0x01e7, 0x0000, 0x0000, 0x01d2, 0x0000, 0x0275, /* 0x16b8-0x16bf */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x018f, 0x0000, /* 0x16c0-0x16c7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16c8-0x16cf */
0x0000, 0x1e36, 0xf0d2, 0xf0d3, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16d0-0x16d7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16d8-0x16df */
0x0000, 0x1e37, 0xf0e2, 0xf0e3, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16e0-0x16e7 */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16e8-0x16ef */
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0259 /* 0x16f0-0x16f6 */
};
static unsigned short const keysym_to_unicode_1e9f_1eff[] = {
0x0303,
0x1ea0, 0x1ea1, 0x1ea2, 0x1ea3, 0x1ea4, 0x1ea5, 0x1ea6, 0x1ea7, /* 0x1ea0-0x1ea7 */
0x1ea8, 0x1ea9, 0x1eaa, 0x1eab, 0x1eac, 0x1ead, 0x1eae, 0x1eaf, /* 0x1ea8-0x1eaf */
0x1eb0, 0x1eb1, 0x1eb2, 0x1eb3, 0x1eb4, 0x1eb5, 0x1eb6, 0x1eb7, /* 0x1eb0-0x1eb7 */
0x1eb8, 0x1eb9, 0x1eba, 0x1ebb, 0x1ebc, 0x1ebd, 0x1ebe, 0x1ebf, /* 0x1eb8-0x1ebf */
0x1ec0, 0x1ec1, 0x1ec2, 0x1ec3, 0x1ec4, 0x1ec5, 0x1ec6, 0x1ec7, /* 0x1ec0-0x1ec7 */
0x1ec8, 0x1ec9, 0x1eca, 0x1ecb, 0x1ecc, 0x1ecd, 0x1ece, 0x1ecf, /* 0x1ec8-0x1ecf */
0x1ed0, 0x1ed1, 0x1ed2, 0x1ed3, 0x1ed4, 0x1ed5, 0x1ed6, 0x1ed7, /* 0x1ed0-0x1ed7 */
0x1ed8, 0x1ed9, 0x1eda, 0x1edb, 0x1edc, 0x1edd, 0x1ede, 0x1edf, /* 0x1ed8-0x1edf */
0x1ee0, 0x1ee1, 0x1ee2, 0x1ee3, 0x1ee4, 0x1ee5, 0x1ee6, 0x1ee7, /* 0x1ee0-0x1ee7 */
0x1ee8, 0x1ee9, 0x1eea, 0x1eeb, 0x1eec, 0x1eed, 0x1eee, 0x1eef, /* 0x1ee8-0x1eef */
0x1ef0, 0x1ef1, 0x0300, 0x0301, 0x1ef4, 0x1ef5, 0x1ef6, 0x1ef7, /* 0x1ef0-0x1ef7 */
0x1ef8, 0x1ef9, 0x01a0, 0x01a1, 0x01af, 0x01b0, 0x0309, 0x0323 /* 0x1ef8-0x1eff */
};
static unsigned short const keysym_to_unicode_20a0_20ac[] = {
0x20a0, 0x20a1, 0x20a2, 0x20a3, 0x20a4, 0x20a5, 0x20a6, 0x20a7, /* 0x20a0-0x20a7 */
0x20a8, 0x20a9, 0x20aa, 0x20ab, 0x20ac /* 0x20a8-0x20af */
};
unsigned int
KeySymToUcs4(KeySym keysym)
{
/* 'Unicode keysym' */
if ((keysym & 0xff000000) == 0x01000000)
return (keysym & 0x00ffffff);
if (keysym > 0 && keysym < 0x100)
return keysym;
else if (keysym > 0x1a0 && keysym < 0x200)
return keysym_to_unicode_1a1_1ff[keysym - 0x1a1];
else if (keysym > 0x2a0 && keysym < 0x2ff)
return keysym_to_unicode_2a1_2fe[keysym - 0x2a1];
else if (keysym > 0x3a1 && keysym < 0x3ff)
return keysym_to_unicode_3a2_3fe[keysym - 0x3a2];
else if (keysym > 0x4a0 && keysym < 0x4e0)
return keysym_to_unicode_4a1_4df[keysym - 0x4a1];
else if (keysym > 0x589 && keysym < 0x5ff)
return keysym_to_unicode_590_5fe[keysym - 0x590];
else if (keysym > 0x67f && keysym < 0x700)
return keysym_to_unicode_680_6ff[keysym - 0x680];
else if (keysym > 0x7a0 && keysym < 0x7fa)
return keysym_to_unicode_7a1_7f9[keysym - 0x7a1];
else if (keysym > 0x8a3 && keysym < 0x8ff)
return keysym_to_unicode_8a4_8fe[keysym - 0x8a4];
else if (keysym > 0x9de && keysym < 0x9f9)
return keysym_to_unicode_9df_9f8[keysym - 0x9df];
else if (keysym > 0xaa0 && keysym < 0xaff)
return keysym_to_unicode_aa1_afe[keysym - 0xaa1];
else if (keysym > 0xcde && keysym < 0xcfb)
return keysym_to_unicode_cdf_cfa[keysym - 0xcdf];
else if (keysym > 0xda0 && keysym < 0xdfa)
return keysym_to_unicode_da1_df9[keysym - 0xda1];
else if (keysym > 0xe9f && keysym < 0xf00)
return keysym_to_unicode_ea0_eff[keysym - 0xea0];
else if (keysym > 0x12a0 && keysym < 0x12ff)
return keysym_to_unicode_12a1_12fe[keysym - 0x12a1];
else if (keysym > 0x13bb && keysym < 0x13bf)
return keysym_to_unicode_13bc_13be[keysym - 0x13bc];
else if (keysym > 0x14a0 && keysym < 0x1500)
return keysym_to_unicode_14a1_14ff[keysym - 0x14a1];
else if (keysym > 0x15cf && keysym < 0x15f7)
return keysym_to_unicode_15d0_15f6[keysym - 0x15d0];
else if (keysym > 0x169f && keysym < 0x16f7)
return keysym_to_unicode_16a0_16f6[keysym - 0x16a0];
else if (keysym > 0x1e9e && keysym < 0x1f00)
return keysym_to_unicode_1e9f_1eff[keysym - 0x1e9f];
else if (keysym > 0x209f && keysym < 0x20ad)
return keysym_to_unicode_20a0_20ac[keysym - 0x20a0];
else
return 0;
}
|
astrangeguy/libx11-debian-mirror
|
src/Font.c
|
/*
Copyright 1986, 1998 The Open Group
Copyright (c) 2000 The XFree86 Project, Inc.
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM OR THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Except as contained in this notice, the name of the X Consortium or of the
XFree86 Project shall not be used in advertising or otherwise to promote the
sale, use or other dealings in this Software without prior written
authorization from the X Consortium and the XFree86 Project.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#if defined(XF86BIGFONT) && !defined(MUSTCOPY)
#define USE_XF86BIGFONT
#endif
#ifdef USE_XF86BIGFONT
#include <sys/types.h>
#ifdef HAS_SHM
#include <sys/ipc.h>
#include <sys/shm.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <X11/extensions/xf86bigfproto.h>
#endif
#include "Xlcint.h"
#include "XlcPubI.h"
static XFontStruct *_XQueryFont(
Display* /* dpy */,
Font /* fid */,
unsigned long /* seq */
);
#ifdef USE_XF86BIGFONT
/* Private data for this extension. */
typedef struct {
XExtCodes *codes;
CARD32 serverSignature;
CARD32 serverCapabilities;
} XF86BigfontCodes;
/* Additional bit masks that can be set in serverCapabilities */
#define CAP_VerifiedLocal 256
static XF86BigfontCodes *_XF86BigfontCodes(
Display* /* dpy */
);
static XFontStruct *_XF86BigfontQueryFont(
Display* /* dpy */,
XF86BigfontCodes* /* extcodes */,
Font /* fid */,
unsigned long /* seq */
);
void _XF86BigfontFreeFontMetrics(
XFontStruct* /* fs */
);
#endif /* USE_XF86BIGFONT */
XFontStruct *XLoadQueryFont(
register Display *dpy,
_Xconst char *name)
{
XFontStruct *font_result;
register long nbytes;
Font fid;
xOpenFontReq *req;
unsigned long seq;
#ifdef USE_XF86BIGFONT
XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
#endif
if (_XF86LoadQueryLocaleFont(dpy, name, &font_result, (Font *)0))
return font_result;
LockDisplay(dpy);
GetReq(OpenFont, req);
seq = dpy->request;
nbytes = req->nbytes = name ? strlen(name) : 0;
req->fid = fid = XAllocID(dpy);
req->length += (nbytes+3)>>2;
Data (dpy, name, nbytes);
font_result = NULL;
#ifdef USE_XF86BIGFONT
if (extcodes) {
font_result = _XF86BigfontQueryFont(dpy, extcodes, fid, seq);
seq = 0;
}
#endif
if (!font_result)
font_result = _XQueryFont(dpy, fid, seq);
UnlockDisplay(dpy);
SyncHandle();
return font_result;
}
XFontStruct *XQueryFont (
register Display *dpy,
Font fid)
{
XFontStruct *font_result;
#ifdef USE_XF86BIGFONT
XF86BigfontCodes *extcodes = _XF86BigfontCodes(dpy);
#endif
LockDisplay(dpy);
font_result = NULL;
#ifdef USE_XF86BIGFONT
if (extcodes) {
font_result = _XF86BigfontQueryFont(dpy, extcodes, fid, 0L);
}
#endif
if (!font_result)
font_result = _XQueryFont(dpy, fid, 0L);
UnlockDisplay(dpy);
SyncHandle();
return font_result;
}
int
XFreeFont(
register Display *dpy,
XFontStruct *fs)
{
register xResourceReq *req;
register _XExtension *ext;
LockDisplay(dpy);
/* call out to any extensions interested */
for (ext = dpy->ext_procs; ext; ext = ext->next)
if (ext->free_Font) (*ext->free_Font)(dpy, fs, &ext->codes);
GetResReq (CloseFont, fs->fid, req);
UnlockDisplay(dpy);
SyncHandle();
if (fs->per_char) {
#ifdef USE_XF86BIGFONT
_XF86BigfontFreeFontMetrics(fs);
#else
Xfree ((char *) fs->per_char);
#endif
}
_XFreeExtData(fs->ext_data);
if (fs->properties)
Xfree ((char *) fs->properties);
Xfree ((char *) fs);
return 1;
}
static XFontStruct *
_XQueryFont (
register Display *dpy,
Font fid,
unsigned long seq)
{
register XFontStruct *fs;
register long nbytes;
xQueryFontReply reply;
register xResourceReq *req;
register _XExtension *ext;
_XAsyncHandler async;
_XAsyncErrorState async_state;
if (seq) {
async_state.min_sequence_number = seq;
async_state.max_sequence_number = seq;
async_state.error_code = BadName;
async_state.major_opcode = X_OpenFont;
async_state.minor_opcode = 0;
async_state.error_count = 0;
async.next = dpy->async_handlers;
async.handler = _XAsyncErrorHandler;
async.data = (XPointer)&async_state;
dpy->async_handlers = &async;
}
GetResReq(QueryFont, fid, req);
if (!_XReply (dpy, (xReply *) &reply,
((SIZEOF(xQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) {
if (seq)
DeqAsyncHandler(dpy, &async);
return (XFontStruct *)NULL;
}
if (seq)
DeqAsyncHandler(dpy, &async);
if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) {
_XEatData(dpy, (unsigned long)(reply.nFontProps * SIZEOF(xFontProp) +
reply.nCharInfos * SIZEOF(xCharInfo)));
return (XFontStruct *)NULL;
}
fs->ext_data = NULL;
fs->fid = fid;
fs->direction = reply.drawDirection;
fs->min_char_or_byte2 = reply.minCharOrByte2;
fs->max_char_or_byte2 = reply.maxCharOrByte2;
fs->min_byte1 = reply.minByte1;
fs->max_byte1 = reply.maxByte1;
fs->default_char = reply.defaultChar;
fs->all_chars_exist = reply.allCharsExist;
fs->ascent = cvtINT16toInt (reply.fontAscent);
fs->descent = cvtINT16toInt (reply.fontDescent);
#ifdef MUSTCOPY
{
xCharInfo *xcip;
xcip = (xCharInfo *) &reply.minBounds;
fs->min_bounds.lbearing = cvtINT16toShort(xcip->leftSideBearing);
fs->min_bounds.rbearing = cvtINT16toShort(xcip->rightSideBearing);
fs->min_bounds.width = cvtINT16toShort(xcip->characterWidth);
fs->min_bounds.ascent = cvtINT16toShort(xcip->ascent);
fs->min_bounds.descent = cvtINT16toShort(xcip->descent);
fs->min_bounds.attributes = xcip->attributes;
xcip = (xCharInfo *) &reply.maxBounds;
fs->max_bounds.lbearing = cvtINT16toShort(xcip->leftSideBearing);
fs->max_bounds.rbearing = cvtINT16toShort(xcip->rightSideBearing);
fs->max_bounds.width = cvtINT16toShort(xcip->characterWidth);
fs->max_bounds.ascent = cvtINT16toShort(xcip->ascent);
fs->max_bounds.descent = cvtINT16toShort(xcip->descent);
fs->max_bounds.attributes = xcip->attributes;
}
#else
/* XXX the next two statements won't work if short isn't 16 bits */
fs->min_bounds = * (XCharStruct *) &reply.minBounds;
fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
#endif /* MUSTCOPY */
fs->n_properties = reply.nFontProps;
/*
* if no properties defined for the font, then it is bad
* font, but shouldn't try to read nothing.
*/
fs->properties = NULL;
if (fs->n_properties > 0) {
nbytes = reply.nFontProps * sizeof(XFontProp);
fs->properties = (XFontProp *) Xmalloc ((unsigned) nbytes);
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if (! fs->properties) {
Xfree((char *) fs);
_XEatData(dpy, (unsigned long)
(nbytes + reply.nCharInfos * SIZEOF(xCharInfo)));
return (XFontStruct *)NULL;
}
_XRead32 (dpy, (long *)fs->properties, nbytes);
}
/*
* If no characters in font, then it is a bad font, but
* shouldn't try to read nothing.
*/
/* have to unpack charinfos on some machines (CRAY) */
fs->per_char = NULL;
if (reply.nCharInfos > 0){
nbytes = reply.nCharInfos * sizeof(XCharStruct);
if (! (fs->per_char = (XCharStruct *) Xmalloc ((unsigned) nbytes))) {
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
_XEatData(dpy, (unsigned long)
(reply.nCharInfos * SIZEOF(xCharInfo)));
return (XFontStruct *)NULL;
}
#ifdef MUSTCOPY
{
register XCharStruct *cs = fs->per_char;
register int i;
for (i = 0; i < reply.nCharInfos; i++, cs++) {
xCharInfo xcip;
_XRead(dpy, (char *)&xcip, SIZEOF(xCharInfo));
cs->lbearing = cvtINT16toShort(xcip.leftSideBearing);
cs->rbearing = cvtINT16toShort(xcip.rightSideBearing);
cs->width = cvtINT16toShort(xcip.characterWidth);
cs->ascent = cvtINT16toShort(xcip.ascent);
cs->descent = cvtINT16toShort(xcip.descent);
cs->attributes = xcip.attributes;
}
}
#else
nbytes = reply.nCharInfos * SIZEOF(xCharInfo);
_XRead16 (dpy, (char *)fs->per_char, nbytes);
#endif
}
/* call out to any extensions interested */
for (ext = dpy->ext_procs; ext; ext = ext->next)
if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes);
return fs;
}
#ifdef USE_XF86BIGFONT
/* Magic cookie for finding the right XExtData structure on the display's
extension list. */
static int XF86BigfontNumber = 1040697125;
static int
_XF86BigfontFreeCodes (
XExtData *extension)
{
/* Don't Xfree(extension->private_data) because it is on the same malloc
chunk as extension. */
/* Don't Xfree(extension->private_data->codes) because this is shared with
the display's ext_procs list. */
return 0;
}
static XF86BigfontCodes *
_XF86BigfontCodes (
register Display *dpy)
{
XEDataObject dpy_union;
XExtData *pData;
XF86BigfontCodes *pCodes;
char *envval;
dpy_union.display = dpy;
/* If the server is known to support the XF86Bigfont extension,
* return the extension codes. If the server is known to not support
* the extension, don't bother checking again.
*/
pData = XFindOnExtensionList(XEHeadOfExtensionList(dpy_union),
XF86BigfontNumber);
if (pData)
return (XF86BigfontCodes *) pData->private_data;
pData = (XExtData *) Xmalloc(sizeof(XExtData) + sizeof(XF86BigfontCodes));
if (!pData) {
/* Out of luck. */
return (XF86BigfontCodes *) NULL;
}
/* See if the server supports the XF86Bigfont extension. */
envval = getenv("XF86BIGFONT_DISABLE"); /* Let the user disable it. */
if (envval != NULL && envval[0] != '\0')
pCodes = NULL;
else {
XExtCodes *codes = XInitExtension(dpy, XF86BIGFONTNAME);
if (codes == NULL)
pCodes = NULL;
else {
pCodes = (XF86BigfontCodes *) &pData[1];
pCodes->codes = codes;
}
}
pData->number = XF86BigfontNumber;
pData->private_data = (XPointer) pCodes;
pData->free_private = _XF86BigfontFreeCodes;
XAddToExtensionList(XEHeadOfExtensionList(dpy_union), pData);
if (pCodes) {
int result;
/* See if the server supports the XF86BigfontQueryFont request. */
xXF86BigfontQueryVersionReply reply;
register xXF86BigfontQueryVersionReq *req;
LockDisplay(dpy);
GetReq(XF86BigfontQueryVersion, req);
req->reqType = pCodes->codes->major_opcode;
req->xf86bigfontReqType = X_XF86BigfontQueryVersion;
result = _XReply (dpy, (xReply *) &reply,
(SIZEOF(xXF86BigfontQueryVersionReply) - SIZEOF(xReply)) >> 2,
xFalse);
UnlockDisplay(dpy);
SyncHandle();
if(!result)
goto ignore_extension;
/* No need to provide backward compatibility with version 1.0. It
was never widely distributed. */
if (!(reply.majorVersion > 1
|| (reply.majorVersion == 1 && reply.minorVersion >= 1)))
goto ignore_extension;
pCodes->serverSignature = reply.signature;
pCodes->serverCapabilities = reply.capabilities;
}
return pCodes;
ignore_extension:
/* No need to Xfree(pCodes) or Xfree(pCodes->codes), see
_XF86BigfontFreeCodes comment. */
pCodes = (XF86BigfontCodes *) NULL;
pData->private_data = (XPointer) pCodes;
return pCodes;
}
static int
_XF86BigfontFreeNop (
XExtData *extension)
{
return 0;
}
static XFontStruct *
_XF86BigfontQueryFont (
register Display *dpy,
XF86BigfontCodes *extcodes,
Font fid,
unsigned long seq)
{
register XFontStruct *fs;
register long nbytes;
xXF86BigfontQueryFontReply reply;
register xXF86BigfontQueryFontReq *req;
register _XExtension *ext;
_XAsyncHandler async1;
_XAsyncErrorState async1_state;
_XAsyncHandler async2;
_XAsyncErrorState async2_state;
if (seq) {
async1_state.min_sequence_number = seq;
async1_state.max_sequence_number = seq;
async1_state.error_code = BadName;
async1_state.major_opcode = X_OpenFont;
async1_state.minor_opcode = 0;
async1_state.error_count = 0;
async1.next = dpy->async_handlers;
async1.handler = _XAsyncErrorHandler;
async1.data = (XPointer)&async1_state;
dpy->async_handlers = &async1;
}
GetReq(XF86BigfontQueryFont, req);
req->reqType = extcodes->codes->major_opcode;
req->xf86bigfontReqType = X_XF86BigfontQueryFont;
req->id = fid;
req->flags = (extcodes->serverCapabilities & XF86Bigfont_CAP_LocalShm
? XF86Bigfont_FLAGS_Shm : 0);
/* The function _XQueryFont benefits from a "magic" error handler for
BadFont coming from a X_QueryFont request. (See function _XReply.)
We have to establish an error handler ourselves. */
async2_state.min_sequence_number = dpy->request;
async2_state.max_sequence_number = dpy->request;
async2_state.error_code = BadFont;
async2_state.major_opcode = extcodes->codes->major_opcode;
async2_state.minor_opcode = X_XF86BigfontQueryFont;
async2_state.error_count = 0;
async2.next = dpy->async_handlers;
async2.handler = _XAsyncErrorHandler;
async2.data = (XPointer)&async2_state;
dpy->async_handlers = &async2;
if (!_XReply (dpy, (xReply *) &reply,
((SIZEOF(xXF86BigfontQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) {
DeqAsyncHandler(dpy, &async2);
if (seq)
DeqAsyncHandler(dpy, &async1);
return (XFontStruct *)NULL;
}
DeqAsyncHandler(dpy, &async2);
if (seq)
DeqAsyncHandler(dpy, &async1);
if (! (fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct)))) {
_XEatData(dpy,
reply.nFontProps * SIZEOF(xFontProp)
+ (reply.nCharInfos > 0 && reply.shmid == (CARD32)(-1)
? reply.nUniqCharInfos * SIZEOF(xCharInfo)
+ (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16)
: 0));
return (XFontStruct *)NULL;
}
fs->ext_data = NULL;
fs->fid = fid;
fs->direction = reply.drawDirection;
fs->min_char_or_byte2 = reply.minCharOrByte2;
fs->max_char_or_byte2 = reply.maxCharOrByte2;
fs->min_byte1 = reply.minByte1;
fs->max_byte1 = reply.maxByte1;
fs->default_char = reply.defaultChar;
fs->all_chars_exist = reply.allCharsExist;
fs->ascent = cvtINT16toInt (reply.fontAscent);
fs->descent = cvtINT16toInt (reply.fontDescent);
/* XXX the next two statements won't work if short isn't 16 bits */
fs->min_bounds = * (XCharStruct *) &reply.minBounds;
fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
fs->n_properties = reply.nFontProps;
/*
* if no properties defined for the font, then it is bad
* font, but shouldn't try to read nothing.
*/
fs->properties = NULL;
if (fs->n_properties > 0) {
nbytes = reply.nFontProps * sizeof(XFontProp);
fs->properties = (XFontProp *) Xmalloc ((unsigned) nbytes);
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if (! fs->properties) {
Xfree((char *) fs);
_XEatData(dpy,
nbytes
+ (reply.nCharInfos > 0 && reply.shmid == (CARD32)(-1)
? reply.nUniqCharInfos * SIZEOF(xCharInfo)
+ (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16)
: 0));
return (XFontStruct *)NULL;
}
_XRead32 (dpy, (long *)fs->properties, nbytes);
}
fs->per_char = NULL;
if (reply.nCharInfos > 0) {
/* fprintf(stderr, "received font metrics, nCharInfos = %d, nUniqCharInfos = %d, shmid = %d\n", reply.nCharInfos, reply.nUniqCharInfos, reply.shmid); */
if (reply.shmid == (CARD32)(-1)) {
xCharInfo* pUniqCI;
CARD16* pIndex2UniqIndex;
int i;
nbytes = reply.nUniqCharInfos * SIZEOF(xCharInfo)
+ (reply.nCharInfos+1)/2 * 2 * sizeof(CARD16);
pUniqCI = (xCharInfo *) Xmalloc (nbytes);
if (!pUniqCI) {
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
_XEatData(dpy, nbytes);
return (XFontStruct *)NULL;
}
if (! (fs->per_char = (XCharStruct *) Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
Xfree((char *) pUniqCI);
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
_XEatData(dpy, nbytes);
return (XFontStruct *)NULL;
}
_XRead16 (dpy, (char *) pUniqCI, nbytes);
pIndex2UniqIndex = (CARD16*) (pUniqCI + reply.nUniqCharInfos);
for (i = 0; i < reply.nCharInfos; i++) {
if (pIndex2UniqIndex[i] >= reply.nUniqCharInfos) {
fprintf(stderr, "_XF86BigfontQueryFont: server returned wrong data\n");
Xfree((char *) pUniqCI);
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
return (XFontStruct *)NULL;
}
/* XXX the next statement won't work if short isn't 16 bits */
fs->per_char[i] = * (XCharStruct *) &pUniqCI[pIndex2UniqIndex[i]];
}
Xfree((char *) pUniqCI);
} else {
#ifdef HAS_SHM
XExtData *pData;
XEDataObject fs_union;
char *addr;
pData = (XExtData *) Xmalloc(sizeof(XExtData));
if (!pData) {
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
return (XFontStruct *)NULL;
}
/* In some cases (e.g. an ssh daemon forwarding an X session to
a remote machine) it is possible that the X server thinks we
are running on the same machine (because getpeername() and
LocalClient() cannot know about the forwarding) but we are
not really local. Therefore, when we attach the first shared
memory segment, we verify that we are on the same machine as
the X server by checking that 1. shmat() succeeds, 2. the
segment has a sufficient size, 3. it contains the X server's
signature. Then we set the CAP_VerifiedLocal bit to indicate
the verification was successful. */
if ((addr = shmat(reply.shmid, NULL, SHM_RDONLY)) == (char *)-1) {
if (extcodes->serverCapabilities & CAP_VerifiedLocal)
fprintf(stderr, "_XF86BigfontQueryFont: could not attach shm segment\n");
Xfree((char *) pData);
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
/* Stop requesting shared memory transport from now on. */
extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
return (XFontStruct *)NULL;
}
if (!(extcodes->serverCapabilities & CAP_VerifiedLocal)) {
struct shmid_ds buf;
if (!(shmctl(reply.shmid, IPC_STAT, &buf) >= 0
&& buf.shm_segsz >= reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct) + sizeof(CARD32)
&& *(CARD32 *)(addr + reply.shmsegoffset + reply.nCharInfos * sizeof(XCharStruct)) == extcodes->serverSignature)) {
shmdt(addr);
Xfree((char *) pData);
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
/* Stop requesting shared memory transport from now on. */
extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
return (XFontStruct *)NULL;
}
extcodes->serverCapabilities |= CAP_VerifiedLocal;
}
pData->number = XF86BigfontNumber;
pData->private_data = (XPointer) addr;
pData->free_private = _XF86BigfontFreeNop;
fs_union.font = fs;
XAddToExtensionList(XEHeadOfExtensionList(fs_union), pData);
fs->per_char = (XCharStruct *) (addr + reply.shmsegoffset);
#else
fprintf(stderr, "_XF86BigfontQueryFont: try recompiling libX11 with HasShm, Xserver has shm support\n");
if (fs->properties) Xfree((char *) fs->properties);
Xfree((char *) fs);
/* Stop requesting shared memory transport from now on. */
extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm;
return (XFontStruct *)NULL;
#endif
}
}
/* call out to any extensions interested */
for (ext = dpy->ext_procs; ext; ext = ext->next)
if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes);
return fs;
}
void
_XF86BigfontFreeFontMetrics (XFontStruct *fs)
{
#ifdef HAS_SHM
XExtData *pData;
XEDataObject fs_union;
fs_union.font = fs;
if ((pData = XFindOnExtensionList(XEHeadOfExtensionList(fs_union),
XF86BigfontNumber)))
shmdt ((char *) pData->private_data);
else
Xfree ((char *) fs->per_char);
#else
Xfree ((char *) fs->per_char);
#endif
}
#endif /* USE_XF86BIGFONT */
int _XF86LoadQueryLocaleFont(
Display *dpy,
_Xconst char *name,
XFontStruct **xfp,
Font *fidp)
{
int l;
const char *charset, *p;
char buf[256];
XFontStruct *fs;
XLCd lcd;
if (!name)
return 0;
l = strlen(name);
if (l < 2 || name[l - 1] != '*' || name[l - 2] != '-')
return 0;
charset = NULL;
/* next three lines stolen from _XkbGetCharset() */
lcd = _XlcCurrentLC();
if ((lcd = _XlcCurrentLC()) != 0)
charset = XLC_PUBLIC(lcd, encoding_name);
if (!charset || (p = strrchr(charset, '-')) == 0 || p == charset || p[1] == 0 || (p[1] == '*' && p[2] == 0)) {
/* prefer latin1 if no encoding found */
charset = "ISO8859-1";
p = charset + 7;
}
if (l - 2 - (p - charset) < 0)
return 0;
if (_XlcNCompareISOLatin1(name + l - 2 - (p - charset), charset, p - charset))
return 0;
if (strlen(p + 1) + l - 1 >= sizeof(buf) - 1)
return 0;
strcpy(buf, name);
strcpy(buf + l - 1, p + 1);
fs = XLoadQueryFont(dpy, buf);
if (!fs)
return 0;
if (xfp) {
*xfp = fs;
if (fidp)
*fidp = fs->fid;
} else if (fidp) {
if (fs->per_char) {
#ifdef USE_XF86BIGFONT
_XF86BigfontFreeFontMetrics(fs);
#else
Xfree ((char *) fs->per_char);
#endif
}
_XFreeExtData(fs->ext_data);
if (fs->properties)
Xfree ((char *) fs->properties);
*fidp = fs->fid;
Xfree ((char *) fs);
} else {
XFreeFont(dpy, fs);
}
return 1;
}
|
astrangeguy/libx11-debian-mirror
|
modules/im/ximcp/imTrX.c
|
<reponame>astrangeguy/libx11-debian-mirror
/*
* Copyright 1992 Oracle and/or its affiliates. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/******************************************************************
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation, and that the name of FUJITSU LIMITED
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission.
FUJITSU LIMITED makes no representations about the suitability of
this software for any purpose.
It is provided "as is" without express or implied warranty.
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Author: <NAME> (<EMAIL>) Sun Microsystems, Inc.
<NAME> FUJITSU LIMITED
<EMAIL>
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <X11/Xatom.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "Ximint.h"
#include "XimTrInt.h"
#include "XimTrX.h"
Private Bool
_XimXRegisterDispatcher(
Xim im,
Bool (*callback)(
Xim, INT16, XPointer, XPointer
),
XPointer call_data)
{
XIntrCallbackPtr rec;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
if (!(rec = (XIntrCallbackPtr)Xmalloc(sizeof(XIntrCallbackRec))))
return False;
rec->func = callback;
rec->call_data = call_data;
rec->next = spec->intr_cb;
spec->intr_cb = rec;
return True;
}
Private void
_XimXFreeIntrCallback(
Xim im)
{
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
register XIntrCallbackPtr rec, next;
for (rec = spec->intr_cb; rec;) {
next = rec->next;
Xfree(rec);
rec = next;
}
return;
}
Private Bool
_XimXCallDispatcher(Xim im, INT16 len, XPointer data)
{
register XIntrCallbackRec *rec;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
for (rec = spec->intr_cb; rec; rec = rec->next) {
if ((*rec->func)(im, len, data, rec->call_data))
return True;
}
return False;
}
Private Bool
_XimXFilterWaitEvent(
Display *d,
Window w,
XEvent *ev,
XPointer arg)
{
Xim im = (Xim)arg;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
Bool ret;
spec->ev = (XPointer)ev;
ret = _XimFilterWaitEvent(im);
/*
* If ev is a pointer to a stack variable, there could be
* a coredump later on if the pointer is dereferenced.
* Therefore, reset to NULL to force reinitialization in
* _XimXRead().
*
* Keep in mind _XimXRead may be called again when the stack
* is very different.
*/
spec->ev = (XPointer)NULL;
return ret;
}
Private Bool
_CheckConnect(
Display *display,
XEvent *event,
XPointer xim)
{
Xim im = (Xim)xim;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
if ((event->type == ClientMessage)
&& (event->xclient.message_type == spec->imconnectid)) {
return True;
}
return False;
}
Private Bool
_XimXConnect(Xim im)
{
XEvent event;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
CARD32 major_code;
CARD32 minor_code;
if (!(spec->lib_connect_wid = XCreateSimpleWindow(im->core.display,
DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) {
return False;
}
event.xclient.type = ClientMessage;
event.xclient.display = im->core.display;
event.xclient.window = im->private.proto.im_window;
event.xclient.message_type = spec->imconnectid;
event.xclient.format = 32;
event.xclient.data.l[0] = (CARD32)spec->lib_connect_wid;
event.xclient.data.l[1] = spec->major_code;
event.xclient.data.l[2] = spec->minor_code;
event.xclient.data.l[3] = 0;
event.xclient.data.l[4] = 0;
if(event.xclient.data.l[1] == 1 || event.xclient.data.l[1] == 2) {
XWindowAttributes atr;
long event_mask;
XGetWindowAttributes(im->core.display, spec->lib_connect_wid, &atr);
event_mask = atr.your_event_mask | PropertyChangeMask;
XSelectInput(im->core.display, spec->lib_connect_wid, event_mask);
_XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
PropertyNotify, PropertyNotify,
_XimXFilterWaitEvent, (XPointer)im);
}
XSendEvent(im->core.display, im->private.proto.im_window,
False, NoEventMask, &event);
XFlush(im->core.display);
for (;;) {
XIfEvent(im->core.display, &event, _CheckConnect, (XPointer)im);
if (event.xclient.type != ClientMessage) {
return False;
}
if (event.xclient.message_type == spec->imconnectid)
break;
}
spec->ims_connect_wid = (Window)event.xclient.data.l[0];
major_code = (CARD32)event.xclient.data.l[1];
minor_code = (CARD32)event.xclient.data.l[2];
if (((major_code == 0) && (minor_code <= 2)) ||
((major_code == 1) && (minor_code == 0)) ||
((major_code == 2) && (minor_code <= 1))) {
spec->major_code = major_code;
spec->minor_code = minor_code;
}
if (((major_code == 0) && (minor_code == 2)) ||
((major_code == 2) && (minor_code == 1))) {
spec->BoundarySize = (CARD32)event.xclient.data.l[3];
}
/* ClientMessage Event Filter */
_XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
ClientMessage, ClientMessage,
_XimXFilterWaitEvent, (XPointer)im);
return True;
}
Private Bool
_XimXShutdown(Xim im)
{
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
if (!spec)
return True;
/* ClientMessage Event Filter */
_XUnregisterFilter(im->core.display,
((XSpecRec *)im->private.proto.spec)->lib_connect_wid,
_XimXFilterWaitEvent, (XPointer)im);
XDestroyWindow(im->core.display,
((XSpecRec *)im->private.proto.spec)->lib_connect_wid);
_XimXFreeIntrCallback(im);
Xfree(spec);
im->private.proto.spec = 0;
return True;
}
Private char *
_NewAtom(
char *atomName)
{
static int sequence = 0;
(void)sprintf(atomName, "_client%d", sequence);
sequence = ((sequence < 20) ? sequence + 1 : 0);
return atomName;
}
Private Bool
_XimXWrite(Xim im, INT16 len, XPointer data)
{
Atom atom;
char atomName[16];
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
XEvent event;
CARD8 *p;
CARD32 major_code = spec->major_code;
CARD32 minor_code = spec->minor_code;
int BoundSize;
bzero(&event,sizeof(XEvent));
event.xclient.type = ClientMessage;
event.xclient.display = im->core.display;
event.xclient.window = spec->ims_connect_wid;
if(major_code == 1 && minor_code == 0) {
BoundSize = 0;
} else if((major_code == 0 && minor_code == 2) ||
(major_code == 2 && minor_code == 1)) {
BoundSize = spec->BoundarySize;
} else if(major_code == 0 && minor_code == 1) {
BoundSize = len;
} else {
BoundSize = XIM_CM_DATA_SIZE;
}
if (len > BoundSize) {
event.xclient.message_type = spec->improtocolid;
atom = XInternAtom(im->core.display, _NewAtom(atomName), False);
XChangeProperty(im->core.display, spec->ims_connect_wid,
atom, XA_STRING, 8, PropModeAppend,
(unsigned char *)data, len);
if(major_code == 0) {
event.xclient.format = 32;
event.xclient.data.l[0] = (long)len;
event.xclient.data.l[1] = (long)atom;
XSendEvent(im->core.display, spec->ims_connect_wid,
False, NoEventMask, &event);
}
} else {
int length;
event.xclient.format = 8;
for(length = 0 ; length < len ; length += XIM_CM_DATA_SIZE) {
p = (CARD8 *)&event.xclient.data.b[0];
if((length + XIM_CM_DATA_SIZE) >= len) {
event.xclient.message_type = spec->improtocolid;
bzero(p, XIM_CM_DATA_SIZE);
memcpy((char *)p, (data + length), (len - length));
} else {
event.xclient.message_type = spec->immoredataid;
memcpy((char *)p, (data + length), XIM_CM_DATA_SIZE);
}
XSendEvent(im->core.display, spec->ims_connect_wid,
False, NoEventMask, &event);
}
}
return True;
}
Private Bool
_XimXGetReadData(
Xim im,
char *buf,
int buf_len,
int *ret_len,
XEvent *event)
{
char *data;
int len;
char tmp_buf[XIM_CM_DATA_SIZE];
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
unsigned long length;
Atom prop;
int return_code;
Atom type_ret;
int format_ret;
unsigned long nitems;
unsigned long bytes_after_ret;
unsigned char *prop_ret;
if ((event->type == ClientMessage) &&
!((event->xclient.message_type == spec->improtocolid) ||
(event->xclient.message_type == spec->immoredataid))) {
/* This event has nothing to do with us,
* FIXME should not have gotten here then...
*/
return False;
} else if ((event->type == ClientMessage) && (event->xclient.format == 8)) {
data = event->xclient.data.b;
if (buf_len >= XIM_CM_DATA_SIZE) {
(void)memcpy(buf, data, XIM_CM_DATA_SIZE);
*ret_len = XIM_CM_DATA_SIZE;
} else {
(void)memcpy(buf, data, buf_len);
len = XIM_CM_DATA_SIZE - buf_len;
(void)memcpy(tmp_buf, &data[buf_len], len);
bzero(data, XIM_CM_DATA_SIZE);
(void)memcpy(data, tmp_buf, len);
XPutBackEvent(im->core.display, event);
*ret_len = buf_len;
}
} else if ((event->type == ClientMessage)
&& (event->xclient.format == 32)) {
length = (unsigned long)event->xclient.data.l[0];
prop = (Atom)event->xclient.data.l[1];
return_code = XGetWindowProperty(im->core.display,
spec->lib_connect_wid, prop, 0L,
(long)((length + 3)/ 4), True, AnyPropertyType,
&type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
if (return_code != Success || format_ret == 0 || nitems == 0) {
if (return_code == Success)
XFree(prop_ret);
return False;
}
if (buf_len >= length) {
(void)memcpy(buf, prop_ret, (int)nitems);
*ret_len = (int)nitems;
if (bytes_after_ret > 0) {
XFree(prop_ret);
if (XGetWindowProperty(im->core.display,
spec->lib_connect_wid, prop, 0L,
((length + bytes_after_ret + 3)/ 4),
True, AnyPropertyType,
&type_ret, &format_ret, &nitems,
&bytes_after_ret,
&prop_ret) == Success) {
XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
XA_STRING, 8, PropModePrepend, &prop_ret[length],
(nitems - length));
} else {
return False;
}
}
} else {
(void)memcpy(buf, prop_ret, buf_len);
*ret_len = buf_len;
len = nitems - buf_len;
if (bytes_after_ret > 0) {
XFree(prop_ret);
if (XGetWindowProperty(im->core.display,
spec->lib_connect_wid, prop, 0L,
((length + bytes_after_ret + 3)/ 4),
True, AnyPropertyType,
&type_ret, &format_ret, &nitems,
&bytes_after_ret, &prop_ret) != Success) {
return False;
}
}
XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
event->xclient.data.l[0] = (long)len;
event->xclient.data.l[1] = (long)prop;
XPutBackEvent(im->core.display, event);
}
XFree(prop_ret);
} else if (event->type == PropertyNotify) {
prop = event->xproperty.atom;
return_code = XGetWindowProperty(im->core.display,
spec->lib_connect_wid, prop, 0L,
1000000L, True, AnyPropertyType,
&type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
if (return_code != Success || format_ret == 0 || nitems == 0) {
if (return_code == Success)
XFree(prop_ret);
return False;
}
if (buf_len >= nitems) {
(void)memcpy(buf, prop_ret, (int)nitems);
*ret_len = (int)nitems;
} else {
(void)memcpy(buf, prop_ret, buf_len);
*ret_len = buf_len;
len = nitems - buf_len;
XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
}
XFree(prop_ret);
}
return True;
}
Private Bool
_CheckCMEvent(
Display *display,
XEvent *event,
XPointer xim)
{
Xim im = (Xim)xim;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
CARD32 major_code = spec->major_code;
if ((event->type == ClientMessage)
&&((event->xclient.message_type == spec->improtocolid) ||
(event->xclient.message_type == spec->immoredataid)))
return True;
if((major_code == 1 || major_code == 2) &&
(event->type == PropertyNotify) &&
(event->xproperty.state == PropertyNewValue))
return True;
return False;
}
Private Bool
_XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len)
{
XEvent *ev;
XEvent event;
int len = 0;
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
XPointer arg = spec->ev;
if (!arg) {
bzero(&event, sizeof(XEvent));
ev = &event;
XIfEvent(im->core.display, ev, _CheckCMEvent, (XPointer)im);
} else {
ev = (XEvent *)arg;
spec->ev = (XPointer)NULL;
}
if (!(_XimXGetReadData(im, recv_buf, buf_len, &len, ev)))
return False;
*ret_len = len;
return True;
}
Private void
_XimXFlush(Xim im)
{
XFlush(im->core.display);
return;
}
Public Bool
_XimXConf(Xim im, char *address)
{
XSpecRec *spec;
if (!(spec = Xcalloc(1, sizeof(XSpecRec))))
return False;
spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False);
spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False);
spec->immoredataid = XInternAtom(im->core.display, _XIM_MOREDATA, False);
spec->major_code = MAJOR_TRANSPORT_VERSION;
spec->minor_code = MINOR_TRANSPORT_VERSION;
im->private.proto.spec = (XPointer)spec;
im->private.proto.connect = _XimXConnect;
im->private.proto.shutdown = _XimXShutdown;
im->private.proto.write = _XimXWrite;
im->private.proto.read = _XimXRead;
im->private.proto.flush = _XimXFlush;
im->private.proto.register_dispatcher = _XimXRegisterDispatcher;
im->private.proto.call_dispatcher = _XimXCallDispatcher;
return True;
}
|
astrangeguy/libx11-debian-mirror
|
src/Cr.h
|
<gh_stars>0
#ifndef _CR_H_
#define _CR_H_
extern int _XUpdateGCCache(
register GC gc,
register unsigned long mask,
register XGCValues *attr);
extern void _XNoticeCreateBitmap(
Display *dpy,
Pixmap pid,
unsigned int width,
unsigned int height);
extern void _XNoticePutBitmap(
Display *dpy,
Drawable draw,
XImage *image);
extern Cursor _XTryShapeBitmapCursor(
Display *dpy,
Pixmap source,
Pixmap mask,
XColor *foreground,
XColor *background,
unsigned int x,
unsigned int y);
#endif /* _CR_H_ */
|
astrangeguy/libx11-debian-mirror
|
src/RegstFlt.c
|
/*
* Copyright 1990, 1991 by OMRON Corporation
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name OMRON not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. OMRON makes no representations
* about the suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*
* OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OMRON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Author: <NAME> OMRON Corporation
* <EMAIL>
* <EMAIL>
*/
/*
Copyright 1990, 1991, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include "Xlcint.h"
static void
_XFreeIMFilters(
Display *display)
{
register XFilterEventList fl;
while ((fl = display->im_filters)) {
display->im_filters = fl->next;
Xfree((char *)fl);
}
}
/*
* Register a filter with the filter machinery by event mask.
*/
void
_XRegisterFilterByMask(
Display *display,
Window window,
unsigned long event_mask,
Bool (*filter)(
Display*, Window, XEvent*, XPointer
),
XPointer client_data)
{
XFilterEventRec *rec;
rec = (XFilterEventList)Xmalloc(sizeof(XFilterEventRec));
if (!rec)
return;
rec->window = window;
rec->event_mask = event_mask;
rec->start_type = 0;
rec->end_type = 0;
rec->filter = filter;
rec->client_data = client_data;
LockDisplay(display);
rec->next = display->im_filters;
display->im_filters = rec;
display->free_funcs->im_filters = _XFreeIMFilters;
UnlockDisplay(display);
}
/*
* Register a filter with the filter machinery by type code.
*/
void
_XRegisterFilterByType(
Display *display,
Window window,
int start_type,
int end_type,
Bool (*filter)(
Display*, Window, XEvent*, XPointer
),
XPointer client_data)
{
XFilterEventRec *rec;
rec = (XFilterEventList)Xmalloc(sizeof(XFilterEventRec));
if (!rec)
return;
rec->window = window;
rec->event_mask = 0;
rec->start_type = start_type;
rec->end_type = end_type;
rec->filter = filter;
rec->client_data = client_data;
LockDisplay(display);
rec->next = display->im_filters;
display->im_filters = rec;
display->free_funcs->im_filters = _XFreeIMFilters;
UnlockDisplay(display);
}
void
_XUnregisterFilter(
Display *display,
Window window,
Bool (*filter)(
Display*, Window, XEvent*, XPointer
),
XPointer client_data)
{
register XFilterEventList *prev, fl;
for (prev = &display->im_filters; (fl = *prev); ) {
if (fl->window == window &&
fl->filter == filter && fl->client_data == client_data) {
*prev = fl->next;
Xfree((char *)fl);
} else
prev = &fl->next;
}
}
|
astrangeguy/libx11-debian-mirror
|
src/xlibi18n/XDefaultIMIF.c
|
/*
Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions: The above copyright notice and this
permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
X Window System is a trademark of The Open Group
OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
logo, LBX, X Window System, and Xinerama are trademarks of the Open
Group. All other trademarks and registered trademarks mentioned herein
are the property of their respective owners. No right, title or
interest in or to any trademark, service mark, logo or trade name of
Sun Microsystems, Inc. or its licensors is granted.
*/
/*
* Copyright 2000 Oracle and/or its affiliates. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "XlcGeneric.h"
#ifndef MAXINT
#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1))
#endif /* !MAXINT */
typedef struct _StaticXIM *StaticXIM;
typedef struct _XIMStaticXIMRec {
/* for CT => MB,WC converter */
XlcConv ctom_conv;
XlcConv ctow_conv;
} XIMStaticXIMRec;
typedef enum {
CREATE_IC = 1,
SET_ICVAL = 2,
GET_ICVAL = 3
} XICOp_t;
typedef struct _StaticXIM {
XIMMethods methods;
XIMCoreRec core;
XIMStaticXIMRec *private;
} StaticXIMRec;
static Status _CloseIM(
XIM
);
static char *_SetIMValues(
XIM, XIMArg *
);
static char *_GetIMValues(
XIM, XIMArg*
);
static XIC _CreateIC(
XIM, XIMArg*
);
static _Xconst XIMMethodsRec local_im_methods = {
_CloseIM, /* close */
_SetIMValues, /* set_values */
_GetIMValues, /* get_values */
_CreateIC, /* create_ic */
NULL, /* ctstombs */
NULL /* ctstowcs */
};
static void _DestroyIC(
XIC
);
static void _SetFocus(
XIC
);
static void _UnsetFocus(
XIC
);
static char* _SetICValues(
XIC, XIMArg *
);
static char* _GetICValues(
XIC, XIMArg *
);
static char *_MbReset(
XIC
);
static wchar_t *_WcReset(
XIC
);
static int _MbLookupString(
XIC, XKeyEvent *, char *, int, KeySym *, Status *
);
static int _WcLookupString(
XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status *
);
static _Xconst XICMethodsRec local_ic_methods = {
_DestroyIC, /* destroy */
_SetFocus, /* set_focus */
_UnsetFocus, /* unset_focus */
_SetICValues, /* set_values */
_GetICValues, /* get_values */
_MbReset, /* mb_reset */
_WcReset, /* wc_reset */
NULL, /* utf8_reset */ /* ??? */
_MbLookupString, /* mb_lookup_string */
_WcLookupString, /* wc_lookup_string */
NULL /* utf8_lookup_string */ /* ??? */
};
XIM
_XDefaultOpenIM(
XLCd lcd,
Display *dpy,
XrmDatabase rdb,
char *res_name,
char *res_class)
{
StaticXIM im;
XIMStaticXIMRec *local_impart;
XlcConv ctom_conv, ctow_conv;
int i;
char *mod;
char buf[BUFSIZ];
if (!(ctom_conv = _XlcOpenConverter(lcd,
XlcNCompoundText, lcd, XlcNMultiByte))) {
return((XIM)NULL);
}
if (!(ctow_conv = _XlcOpenConverter(lcd,
XlcNCompoundText, lcd, XlcNWideChar))) {
return((XIM)NULL);
}
if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
return((XIM)NULL);
}
if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec)))
== (XIMStaticXIMRec *)NULL) {
Xfree(im);
return((XIM)NULL);
}
memset(im, 0, sizeof(StaticXIMRec));
memset(local_impart, 0, sizeof(XIMStaticXIMRec));
buf[0] = '\0';
i = 0;
if ((lcd->core->modifiers) && (*lcd->core->modifiers)) {
#define MODIFIER "@im="
mod = strstr(lcd->core->modifiers, MODIFIER);
if (mod) {
mod += strlen(MODIFIER);
while (*mod && *mod != '@' && i < BUFSIZ - 1) {
buf[i++] = *mod++;
}
buf[i] = '\0';
}
}
#undef MODIFIER
if ((im->core.im_name = Xmalloc(i+1)) == NULL)
goto Error2;
strcpy(im->core.im_name, buf);
im->private = local_impart;
im->methods = (XIMMethods)&local_im_methods;
im->core.lcd = lcd;
im->core.ic_chain = (XIC)NULL;
im->core.display = dpy;
im->core.rdb = rdb;
im->core.res_name = NULL;
im->core.res_class = NULL;
local_impart->ctom_conv = ctom_conv;
local_impart->ctow_conv = ctow_conv;
if ((res_name != NULL) && (*res_name != '\0')){
im->core.res_name = strdup(res_name);
}
if ((res_class != NULL) && (*res_class != '\0')){
im->core.res_class = strdup(res_class);
}
return (XIM)im;
Error2 :
Xfree(im->private);
Xfree(im->core.im_name);
Xfree(im);
_XlcCloseConverter(ctom_conv);
_XlcCloseConverter(ctow_conv);
return(NULL);
}
static Status
_CloseIM(XIM xim)
{
StaticXIM im = (StaticXIM)xim;
_XlcCloseConverter(im->private->ctom_conv);
_XlcCloseConverter(im->private->ctow_conv);
XFree(im->private);
XFree(im->core.im_name);
if (im->core.res_name) XFree(im->core.res_name);
if (im->core.res_class) XFree(im->core.res_class);
return 1; /*bugID 4163122*/
}
static char *
_SetIMValues(
XIM xim,
XIMArg *arg)
{
return(arg->name); /* evil */
}
static char *
_GetIMValues(
XIM xim,
XIMArg *values)
{
XIMArg *p;
XIMStyles *styles;
for (p = values; p->name != NULL; p++) {
if (strcmp(p->name, XNQueryInputStyle) == 0) {
styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles));
*(XIMStyles **)p->value = styles;
styles->count_styles = 1;
styles->supported_styles =
(XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle));
styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
} else {
break;
}
}
return (p->name);
}
static char*
_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
{
XIMArg *p;
char *return_name = NULL;
for (p = values; p != NULL && p->name != NULL; p++) {
if(strcmp(p->name, XNInputStyle) == 0) {
if (mode == CREATE_IC)
ic->core.input_style = (XIMStyle)p->value;
} else if (strcmp(p->name, XNClientWindow) == 0) {
ic->core.client_window = (Window)p->value ;
} else if (strcmp(p->name, XNFocusWindow) == 0) {
ic->core.focus_window = (Window)p->value ;
} else if (strcmp(p->name, XNPreeditAttributes) == 0
|| strcmp(p->name, XNStatusAttributes) == 0) {
return_name = _SetICValueData(ic, (XIMArg*)p->value, mode);
if (return_name) break;
} else {
return_name = p->name;
break;
}
}
return(return_name);
}
static char*
_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
{
XIMArg *p;
char *return_name = NULL;
for (p = values; p->name != NULL; p++) {
if(strcmp(p->name, XNInputStyle) == 0) {
*((XIMStyle *)(p->value)) = ic->core.input_style;
} else if (strcmp(p->name, XNClientWindow) == 0) {
*((Window *)(p->value)) = ic->core.client_window;
} else if (strcmp(p->name, XNFocusWindow) == 0) {
*((Window *)(p->value)) = ic->core.focus_window;
} else if (strcmp(p->name, XNFilterEvents) == 0) {
*((unsigned long *)(p->value))= ic->core.filter_events;
} else if (strcmp(p->name, XNPreeditAttributes) == 0
|| strcmp(p->name, XNStatusAttributes) == 0) {
return_name = _GetICValueData(ic, (XIMArg*)p->value, mode);
if (return_name) break;
} else {
return_name = p->name;
break;
}
}
return(return_name);
}
static XIC
_CreateIC(XIM im, XIMArg *arg)
{
XIC ic;
if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
return ((XIC)NULL);
}
memset(ic, 0, sizeof(XICRec));
ic->methods = (XICMethods)&local_ic_methods;
ic->core.im = im;
ic->core.filter_events = KeyPressMask;
if (_SetICValueData(ic, arg, CREATE_IC) != NULL)
goto err_return;
if (!(ic->core.input_style))
goto err_return;
return (XIC)ic;
err_return:
XFree(ic);
return ((XIC)NULL);
}
static void
_DestroyIC(XIC ic)
{
/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already.
if(ic)
XFree(ic); */
}
static void
_SetFocus(XIC ic)
{
}
static void
_UnsetFocus(XIC ic)
{
}
static char*
_SetICValues(XIC ic, XIMArg *args)
{
char *ret = NULL;
if (!ic) {
return (args->name);
}
ret = _SetICValueData(ic, args, SET_ICVAL);
return(ret);
}
static char*
_GetICValues(XIC ic, XIMArg *args)
{
char *ret = NULL;
if (!ic) {
return (args->name);
}
ret = _GetICValueData(ic, args, GET_ICVAL);
return(ret);
}
static char *
_MbReset(XIC xic)
{
return(NULL);
}
static wchar_t *
_WcReset(XIC xic)
{
return(NULL);
}
static int
_MbLookupString(
XIC xic,
XKeyEvent *ev,
char * buffer,
int bytes,
KeySym *keysym,
Status *status)
{
XComposeStatus NotSupportedYet ;
int length;
length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet);
if (keysym && *keysym == NoSymbol){
*status = XLookupNone;
} else if (length > 0) {
*status = XLookupBoth;
} else {
*status = XLookupKeySym;
}
return(length);
}
static int
_WcLookupString(
XIC xic,
XKeyEvent *ev,
wchar_t * buffer,
int wlen,
KeySym *keysym,
Status *status)
{
XComposeStatus NotSupportedYet ;
int length;
/* In single-byte, mb_len = wc_len */
char *mb_buf = (char *)Xmalloc(wlen);
length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet);
if (keysym && *keysym == NoSymbol){
*status = XLookupNone;
} else if (length > 0) {
*status = XLookupBoth;
} else {
*status = XLookupKeySym;
}
mbstowcs(buffer, mb_buf, length);
XFree(mb_buf);
return(length);
}
|
astrangeguy/libx11-debian-mirror
|
src/StrKeysym.c
|
<reponame>astrangeguy/libx11-debian-mirror
/*
Copyright 1985, 1987, 1990, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <limits.h>
#include "Xlibint.h"
#include <X11/Xresource.h>
#include <X11/keysymdef.h>
#include "Xresinternal.h"
#define NEEDKTABLE
#include "ks_tables.h"
#include "Key.h"
#ifndef KEYSYMDB
#ifndef XKEYSYMDB
#define KEYSYMDB "/usr/lib/X11/XKeysymDB"
#else
#define KEYSYMDB XKEYSYMDB
#endif
#endif
static Bool initialized;
static XrmDatabase keysymdb;
static XrmQuark Qkeysym[2];
XrmDatabase
_XInitKeysymDB(void)
{
if (!initialized)
{
const char *dbname;
XrmInitialize();
/* use and name of this env var is not part of the standard */
/* implementation-dependent feature */
dbname = getenv("XKEYSYMDB");
if (!dbname)
dbname = KEYSYMDB;
keysymdb = XrmGetFileDatabase(dbname);
if (keysymdb)
Qkeysym[0] = XrmStringToQuark("Keysym");
initialized = True;
}
return keysymdb;
}
KeySym
XStringToKeysym(_Xconst char *s)
{
register int i, n;
int h;
register Signature sig = 0;
register const char *p = s;
register int c;
register int idx;
const unsigned char *entry;
unsigned char sig1, sig2;
KeySym val;
while ((c = *p++))
sig = (sig << 1) + c;
i = sig % KTABLESIZE;
h = i + 1;
sig1 = (sig >> 8) & 0xff;
sig2 = sig & 0xff;
n = KMAXHASH;
while ((idx = hashString[i]))
{
entry = &_XkeyTable[idx];
if ((entry[0] == sig1) && (entry[1] == sig2) &&
!strcmp(s, (char *)entry + 6))
{
val = (entry[2] << 24) | (entry[3] << 16) |
(entry[4] << 8) | entry[5];
if (!val)
val = XK_VoidSymbol;
return val;
}
if (!--n)
break;
i += h;
if (i >= KTABLESIZE)
i -= KTABLESIZE;
}
if (!initialized)
(void)_XInitKeysymDB();
if (keysymdb)
{
XrmValue result;
XrmRepresentation from_type;
char c;
XrmQuark names[2];
names[0] = _XrmInternalStringToQuark(s, p - s - 1, sig, False);
names[1] = NULLQUARK;
(void)XrmQGetResource(keysymdb, names, Qkeysym, &from_type, &result);
if (result.addr && (result.size > 1))
{
val = 0;
for (i = 0; i < result.size - 1; i++)
{
c = ((char *)result.addr)[i];
if ('0' <= c && c <= '9') val = (val<<4)+c-'0';
else if ('a' <= c && c <= 'f') val = (val<<4)+c-'a'+10;
else if ('A' <= c && c <= 'F') val = (val<<4)+c-'A'+10;
else return NoSymbol;
}
return val;
}
}
if (*s == 'U') {
val = 0;
for (p = &s[1]; *p; p++) {
c = *p;
if ('0' <= c && c <= '9') val = (val<<4)+c-'0';
else if ('a' <= c && c <= 'f') val = (val<<4)+c-'a'+10;
else if ('A' <= c && c <= 'F') val = (val<<4)+c-'A'+10;
else return NoSymbol;
if (val > 0x10ffff)
return NoSymbol;
}
if (val < 0x20 || (val > 0x7e && val < 0xa0))
return NoSymbol;
if (val < 0x100)
return val;
return val | 0x01000000;
}
if (strlen(s) > 2 && s[0] == '0' && s[1] == 'x') {
char *tmp = NULL;
val = strtoul(s, &tmp, 16);
if (val == ULONG_MAX || (tmp && *tmp != '\0'))
return NoSymbol;
else
return val;
}
/* Stupid inconsistency between the headers and XKeysymDB: the former has
* no separating underscore, while some XF86* syms in the latter did.
* As a last ditch effort, try without. */
if (strncmp(s, "XF86_", 5) == 0) {
KeySym ret;
char *tmp = strdup(s);
if (!tmp)
return NoSymbol;
memmove(&tmp[4], &tmp[5], strlen(s) - 5 + 1);
ret = XStringToKeysym(tmp);
free(tmp);
return ret;
}
return NoSymbol;
}
|
astrangeguy/libx11-debian-mirror
|
src/xcms/CvCols.c
|
<gh_stars>0
/*
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
* All Rights Reserved
*
* This file is a component of an X Window System-specific implementation
* of Xcms based on the TekColor Color Management System. Permission is
* hereby granted to use, copy, modify, sell, and otherwise distribute this
* software and its documentation for any purpose and without fee, provided
* that this copyright, permission, and disclaimer notice is reproduced in
* all copies of this software and in supporting documentation. TekColor
* is a trademark of Tektronix, Inc.
*
* Tektronix makes no representation about the suitability of this software
* for any purpose. It is provided "as is" and with all faults.
*
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
*
*
* NAME
* XcmsCvCols.c
*
* DESCRIPTION
* Xcms API routine that converts between the
* device-independent color spaces.
*
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include "Xcmsint.h"
#include "Cv.h"
/*
* LOCAL DEFINES
*/
#define DD_FORMAT 0x01
#define DI_FORMAT 0x02
#define MIX_FORMAT 0x04
#ifndef MAX
# define MAX(x,y) ((x) > (y) ? (x) : (y))
#endif
/************************************************************************
* *
* PRIVATE ROUTINES *
* *
************************************************************************/
/*
* NAME
* EqualCIEXYZ
*
* SYNOPSIS
*/
static int
EqualCIEXYZ(
XcmsColor *p1, XcmsColor *p2)
/*
* DESCRIPTION
* Compares two XcmsColor structures that are in XcmsCIEXYZFormat
*
* RETURNS
* Returns 1 if equal; 0 otherwise.
*
*/
{
if (p1->format != XcmsCIEXYZFormat || p2->format != XcmsCIEXYZFormat) {
return(0);
}
if ((p1->spec.CIEXYZ.X != p2->spec.CIEXYZ.X)
|| (p1->spec.CIEXYZ.Y != p2->spec.CIEXYZ.Y)
|| (p1->spec.CIEXYZ.Z != p2->spec.CIEXYZ.Z)) {
return(0);
}
return(1);
}
/*
* NAME
* XcmsColorSpace
*
* SYNOPSIS
*/
static XcmsColorSpace *
ColorSpaceOfID(
XcmsCCC ccc,
XcmsColorFormat id)
/*
* DESCRIPTION
* Returns a pointer to the color space structure
* (XcmsColorSpace) associated with the specified color space
* ID.
*
* RETURNS
* Pointer to matching XcmsColorSpace structure if found;
* otherwise NULL.
*/
{
XcmsColorSpace **papColorSpaces;
if (ccc == NULL) {
return(NULL);
}
/*
* First try Device-Independent color spaces
*/
papColorSpaces = _XcmsDIColorSpaces;
if (papColorSpaces != NULL) {
while (*papColorSpaces != NULL) {
if ((*papColorSpaces)->id == id) {
return(*papColorSpaces);
}
papColorSpaces++;
}
}
/*
* Next try Device-Dependent color spaces
*/
papColorSpaces = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces;
if (papColorSpaces != NULL) {
while (*papColorSpaces != NULL) {
if ((*papColorSpaces)->id == id) {
return(*papColorSpaces);
}
papColorSpaces++;
}
}
return(NULL);
}
/*
* NAME
* ValidDIColorSpaceID
*
* SYNOPSIS
*/
static int
ValidDIColorSpaceID(
XcmsColorFormat id)
/*
* DESCRIPTION
* Determines if the specified color space ID is a valid
* Device-Independent color space in the specified Color
* Conversion Context.
*
* RETURNS
* Returns zero if not valid; otherwise non-zero.
*/
{
XcmsColorSpace **papRec;
papRec = _XcmsDIColorSpaces;
if (papRec != NULL) {
while (*papRec != NULL) {
if ((*papRec)->id == id) {
return(1);
}
papRec++;
}
}
return(0);
}
/*
* NAME
* ValidDDColorSpaceID
*
* SYNOPSIS
*/
static int
ValidDDColorSpaceID(
XcmsCCC ccc,
XcmsColorFormat id)
/*
* DESCRIPTION
* Determines if the specified color space ID is a valid
* Device-Dependent color space in the specified Color
* Conversion Context.
*
* RETURNS
* Returns zero if not valid; otherwise non-zero.
*/
{
XcmsColorSpace **papRec;
if (ccc->pPerScrnInfo->state != XcmsInitNone) {
papRec = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces;
while (*papRec != NULL) {
if ((*papRec)->id == id) {
return(1);
}
papRec++;
}
}
return(0);
}
/*
* NAME
* ConvertMixedColors - Convert XcmsColor structures
*
* SYNOPSIS
*/
static Status
ConvertMixedColors(
XcmsCCC ccc,
XcmsColor *pColors_in_out,
XcmsColor *pWhitePt,
unsigned int nColors,
XcmsColorFormat targetFormat,
unsigned char format_flag)
/*
* DESCRIPTION
* This routine will only convert the following types of
* batches:
* DI to DI
* DD to DD
* DD to CIEXYZ
* In other words, it will not convert the following types of
* batches:
* DI to DD
* DD to DI(not CIEXYZ)
*
* format_flag:
* 0x01 : convert Device-Dependent only specifications to the
* target format.
* 0x02 : convert Device-Independent only specifications to the
* target format.
* 0x03 : convert all specifications to the target format.
*
* RETURNS
* XcmsFailure if failed,
* XcmsSuccess if none of the color specifications were
* compressed in the conversion process
* XcmsSuccessWithCompression if at least one of the
* color specifications were compressed in the
* conversion process.
*
*/
{
XcmsColor *pColor, *pColors_start;
XcmsColorFormat format;
Status retval_tmp;
Status retval = XcmsSuccess;
unsigned int iColors;
unsigned int nBatch;
/*
* Convert array of mixed color specifications in batches of
* contiguous formats to the target format
*/
iColors = 0;
while (iColors < nColors) {
/*
* Find contiguous array of color specifications with the
* same format
*/
pColor = pColors_start = pColors_in_out + iColors;
format = pColors_start->format;
nBatch = 0;
while (iColors < nColors && pColor->format == format) {
pColor++;
nBatch++;
iColors++;
}
if (format != targetFormat) {
/*
* Need to convert this batch from current format to target format.
*/
if (XCMS_DI_ID(format) && (format_flag & DI_FORMAT) &&
XCMS_DI_ID(targetFormat)) {
/*
* DI->DI
*
* Format of interest is Device-Independent,
* This batch contains Device-Independent specifications, and
* the Target format is Device-Independent.
*/
retval_tmp = _XcmsDIConvertColors(ccc, pColors_start, pWhitePt,
nBatch, targetFormat);
} else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) &&
(targetFormat == XcmsCIEXYZFormat)) {
/*
* DD->CIEXYZ
*
* Format of interest is Device-Dependent,
* This batch contains Device-Dependent specifications, and
* the Target format is CIEXYZ.
*
* Since DD->CIEXYZ we can use NULL instead of pCompressed.
*/
if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc,
pWhitePt, ScreenWhitePointOfCCC(ccc))) {
/*
* Need to call WhiteAdjustProc (Screen White Point to
* White Point).
*/
retval_tmp = (*ccc->whitePtAdjProc)(ccc,
ScreenWhitePointOfCCC(ccc), pWhitePt,
XcmsCIEXYZFormat, pColors_start, nBatch,
(Bool *)NULL);
} else {
retval_tmp = _XcmsDDConvertColors(ccc, pColors_start,
nBatch, XcmsCIEXYZFormat, (Bool *)NULL);
}
} else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) &&
XCMS_DD_ID(targetFormat)) {
/*
* DD->DD(not CIEXYZ)
*
* Format of interest is Device-Dependent,
* This batch contains Device-Dependent specifications, and
* the Target format is Device-Dependent and not CIEXYZ.
*/
retval_tmp = _XcmsDDConvertColors(ccc, pColors_start, nBatch,
targetFormat, (Bool *)NULL);
} else {
/*
* This routine is called for the wrong reason.
*/
return(XcmsFailure);
}
if (retval_tmp == XcmsFailure) {
return(XcmsFailure);
}
retval = MAX(retval, retval_tmp);
}
}
return(retval);
}
/************************************************************************
* *
* API PRIVATE ROUTINES *
* *
************************************************************************/
/*
* NAME
* _XcmsEqualWhitePts
*
* SYNOPSIS
*/
int
_XcmsEqualWhitePts(XcmsCCC ccc, XcmsColor *pWhitePt1, XcmsColor *pWhitePt2)
/*
* DESCRIPTION
*
* RETURNS
* Returns 0 if not equal; otherwise 1.
*
*/
{
XcmsColor tmp1, tmp2;
memcpy((char *)&tmp1, (char *)pWhitePt1, sizeof(XcmsColor));
memcpy((char *)&tmp2, (char *)pWhitePt2, sizeof(XcmsColor));
if (tmp1.format != XcmsCIEXYZFormat) {
if (_XcmsDIConvertColors(ccc, &tmp1, (XcmsColor *) NULL, 1,
XcmsCIEXYZFormat)==0) {
return(0);
}
}
if (tmp2.format != XcmsCIEXYZFormat) {
if (_XcmsDIConvertColors(ccc, &tmp2, (XcmsColor *) NULL, 1,
XcmsCIEXYZFormat)==0) {
return(0);
}
}
return (EqualCIEXYZ(&tmp1, &tmp2));
}
/*
* NAME
* _XcmsDIConvertColors - Convert XcmsColor structures
*
* SYNOPSIS
*/
Status
_XcmsDIConvertColors(
XcmsCCC ccc,
XcmsColor *pColors_in_out,
XcmsColor *pWhitePt,
unsigned int nColors,
XcmsColorFormat newFormat)
/*
* DESCRIPTION
* Convert XcmsColor structures to another Device-Independent
* form.
*
* Here are some assumptions that this routine makes:
* 1. The calling routine has already checked if
* pColors_in_out->format == newFormat, therefore
* there is no need to check again here.
* 2. The calling routine has already checked nColors,
* therefore this routine assumes nColors > 0.
* 3. The calling routine may want to convert only between
* CIExyY <-> CIEXYZ <-> CIEuvY
* therefore, this routine allows pWhitePt to equal NULL.
*
*
* RETURNS
* XcmsFailure if failed,
* XcmsSuccess if succeeded.
*
*/
{
XcmsColorSpace *pFrom, *pTo;
XcmsDIConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ;
XcmsDIConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ;
XcmsDIConversionProc *to_CIEXYZ_stop, *from_CIEXYZ_start;
XcmsDIConversionProc *tmp;
/*
* Allow pWhitePt to equal NULL. This appropriate when converting
* anywhere between:
* CIExyY <-> CIEXYZ <-> CIEuvY
*/
if (pColors_in_out == NULL ||
!ValidDIColorSpaceID(pColors_in_out->format) ||
!ValidDIColorSpaceID(newFormat)) {
return(XcmsFailure);
}
/*
* Get a handle on the function list for the current specification format
*/
if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format))
== NULL) {
return(XcmsFailure);
}
/*
* Get a handle on the function list for the new specification format
*/
if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) {
return(XcmsFailure);
}
src_to_CIEXYZ = pFrom->to_CIEXYZ;
src_from_CIEXYZ = pFrom->from_CIEXYZ;
dest_to_CIEXYZ = pTo->to_CIEXYZ;
dest_from_CIEXYZ = pTo->from_CIEXYZ;
if (pTo->inverse_flag && pFrom->inverse_flag) {
/*
* Find common function pointers
*/
for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){
for (tmp = dest_to_CIEXYZ; *tmp; tmp++) {
if (*to_CIEXYZ_stop == *tmp) {
goto Continue;
}
}
}
Continue:
/*
* Execute the functions to CIEXYZ, stopping short as necessary
*/
while (src_to_CIEXYZ != to_CIEXYZ_stop) {
if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out,
nColors) == XcmsFailure) {
return(XcmsFailure);
}
}
/*
* Determine where to start on the from_CIEXYZ path.
*/
from_CIEXYZ_start = dest_from_CIEXYZ;
tmp = src_from_CIEXYZ;
while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) {
from_CIEXYZ_start++;
tmp++;
}
} else {
/*
* The function in at least one of the Color Spaces are not
* complementary, i.e.,
* for an i, 0 <= i < n elements
* from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i]
*
* Execute the functions all the way to CIEXYZ
*/
while (*src_to_CIEXYZ) {
if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out,
nColors) == XcmsFailure) {
return(XcmsFailure);
}
}
/*
* Determine where to start on the from_CIEXYZ path.
*/
from_CIEXYZ_start = dest_from_CIEXYZ;
}
/*
* Execute the functions from CIEXYZ.
*/
while (*from_CIEXYZ_start) {
if ((*from_CIEXYZ_start++)(ccc, pWhitePt, pColors_in_out,
nColors) == XcmsFailure) {
return(XcmsFailure);
}
}
return(XcmsSuccess);
}
/*
* NAME
* _XcmsDDConvertColors - Convert XcmsColor structures
*
* SYNOPSIS
*/
Status
_XcmsDDConvertColors(
XcmsCCC ccc,
XcmsColor *pColors_in_out,
unsigned int nColors,
XcmsColorFormat newFormat,
Bool *pCompressed)
/*
* DESCRIPTION
* Convert XcmsColor structures:
*
* 1. From CIEXYZ to Device-Dependent formats (typically RGB and
* RGBi),
* or
* 2. Between Device-Dependent formats (typically RGB and RGBi).
*
* Assumes that these specifications have already been white point
* adjusted if necessary from Client White Point to Screen
* White Point. Therefore, the white point now associated
* with the specifications is the Screen White Point.
*
* pCompressed may be NULL. If so this indicates that the
* calling routine is not interested in knowing exactly which
* color was compressed, if any.
*
*
* RETURNS
* XcmsFailure if failed,
* XcmsSuccess if none of the color specifications were
* compressed in the conversion process
* XcmsSuccessWithCompression if at least one of the
* color specifications were compressed in the
* conversion process.
*
*/
{
XcmsColorSpace *pFrom, *pTo;
XcmsDDConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ;
XcmsDDConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ;
XcmsDDConversionProc *from_CIEXYZ_start, *to_CIEXYZ_stop;
XcmsDDConversionProc *tmp;
int retval;
int hasCompressed = 0;
if (ccc == NULL || pColors_in_out == NULL) {
return(XcmsFailure);
}
if (nColors == 0 || pColors_in_out->format == newFormat) {
/* do nothing */
return(XcmsSuccess);
}
if (((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet) == NULL) {
return(XcmsFailure); /* hmm, an internal error? */
}
/*
* Its ok if pColors_in_out->format == XcmsCIEXYZFormat
* or
* if newFormat == XcmsCIEXYZFormat
*/
if ( !( ValidDDColorSpaceID(ccc, pColors_in_out->format)
||
(pColors_in_out->format == XcmsCIEXYZFormat))
||
!(ValidDDColorSpaceID(ccc, newFormat)
||
newFormat == XcmsCIEXYZFormat)) {
return(XcmsFailure);
}
if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format)) == NULL){
return(XcmsFailure);
}
if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) {
return(XcmsFailure);
}
src_to_CIEXYZ = (XcmsDDConversionProc *)pFrom->to_CIEXYZ;
src_from_CIEXYZ = (XcmsDDConversionProc *)pFrom->from_CIEXYZ;
dest_to_CIEXYZ = (XcmsDDConversionProc *)pTo->to_CIEXYZ;
dest_from_CIEXYZ = (XcmsDDConversionProc *)pTo->from_CIEXYZ;
if (pTo->inverse_flag && pFrom->inverse_flag) {
/*
* Find common function pointers
*/
for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){
for (tmp = dest_to_CIEXYZ; *tmp; tmp++) {
if (*to_CIEXYZ_stop == *tmp) {
goto Continue;
}
}
}
Continue:
/*
* Execute the functions
*/
while (src_to_CIEXYZ != to_CIEXYZ_stop) {
retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors,
pCompressed);
if (retval == XcmsFailure) {
return(XcmsFailure);
}
hasCompressed |= (retval == XcmsSuccessWithCompression);
}
/*
* Determine where to start on the from_CIEXYZ path.
*/
from_CIEXYZ_start = dest_from_CIEXYZ;
tmp = src_from_CIEXYZ;
while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) {
from_CIEXYZ_start++;
tmp++;
}
} else {
/*
* The function in at least one of the Color Spaces are not
* complementary, i.e.,
* for an i, 0 <= i < n elements
* from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i]
*
* Execute the functions all the way to CIEXYZ
*/
while (*src_to_CIEXYZ) {
retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors,
pCompressed);
if (retval == XcmsFailure) {
return(XcmsFailure);
}
hasCompressed |= (retval == XcmsSuccessWithCompression);
}
/*
* Determine where to start on the from_CIEXYZ path.
*/
from_CIEXYZ_start = dest_from_CIEXYZ;
}
while (*from_CIEXYZ_start) {
retval = (*from_CIEXYZ_start++)(ccc, pColors_in_out, nColors,
pCompressed);
if (retval == XcmsFailure) {
return(XcmsFailure);
}
hasCompressed |= (retval == XcmsSuccessWithCompression);
}
return(hasCompressed ? XcmsSuccessWithCompression : XcmsSuccess);
}
/************************************************************************
* *
* PUBLIC ROUTINES *
* *
************************************************************************/
/*
* NAME
* XcmsConvertColors - Convert XcmsColor structures
*
* SYNOPSIS
*/
Status
XcmsConvertColors(
XcmsCCC ccc,
XcmsColor *pColors_in_out,
unsigned int nColors,
XcmsColorFormat targetFormat,
Bool *pCompressed)
/*
* DESCRIPTION
* Convert XcmsColor structures to another format
*
* RETURNS
* XcmsFailure if failed,
* XcmsSuccess if succeeded without gamut compression,
* XcmsSuccessWithCompression if succeeded with gamut
* compression.
*
*/
{
XcmsColor clientWhitePt;
XcmsColor Color1;
XcmsColor *pColors_tmp;
int callWhiteAdjustProc = 0;
XcmsColorFormat format;
Status retval;
unsigned char contents_flag = 0x00;
unsigned int iColors;
if (ccc == NULL || pColors_in_out == NULL ||
!(ValidDIColorSpaceID(targetFormat) ||
ValidDDColorSpaceID(ccc, targetFormat))) {
return(XcmsFailure);
}
/*
* Check formats in color specification array
*/
format = pColors_in_out->format;
for (pColors_tmp = pColors_in_out, iColors = nColors; iColors; pColors_tmp++, iColors--) {
if (!(ValidDIColorSpaceID(pColors_tmp->format) ||
ValidDDColorSpaceID(ccc, pColors_tmp->format))) {
return(XcmsFailure);
}
if (XCMS_DI_ID(pColors_tmp->format)) {
contents_flag |= DI_FORMAT;
} else {
contents_flag |= DD_FORMAT;
}
if (pColors_tmp->format != format) {
contents_flag |= MIX_FORMAT;
}
}
/*
* Check if we need the Client White Point.
*/
if ((contents_flag & DI_FORMAT) || XCMS_DI_ID(targetFormat)) {
/* To proceed, we need to get the Client White Point */
memcpy((char *)&clientWhitePt, (char *)&ccc->clientWhitePt,
sizeof(XcmsColor));
if (clientWhitePt.format == XcmsUndefinedFormat) {
/*
* Client White Point is undefined, therefore set to the Screen
* White Point.
* Since Client White Point == Screen White Point, WhiteAdjustProc
* is not called.
*/
memcpy((char *)&clientWhitePt,
(char *)&ccc->pPerScrnInfo->screenWhitePt,
sizeof(XcmsColor));
} else if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc,
&clientWhitePt, ScreenWhitePointOfCCC(ccc))) {
/*
* Client White Point != Screen White Point, and WhiteAdjustProc
* is not NULL, therefore, will need to call it when
* converting between DI and DD specifications.
*/
callWhiteAdjustProc = 1;
}
}
/*
* Make copy of array of color specifications
*/
if (nColors > 1) {
pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor));
} else {
pColors_tmp = &Color1;
}
memcpy((char *)pColors_tmp, (char *)pColors_in_out,
nColors * sizeof(XcmsColor));
/*
* zero out pCompressed
*/
if (pCompressed) {
bzero((char *)pCompressed, nColors * sizeof(Bool));
}
if (contents_flag == DD_FORMAT || contents_flag == DI_FORMAT) {
/*
* ENTIRE ARRAY IS IN ONE FORMAT.
*/
if (XCMS_DI_ID(format) && XCMS_DI_ID(targetFormat)) {
/*
* DI-to-DI only conversion
*/
retval = _XcmsDIConvertColors(ccc, pColors_tmp,
&clientWhitePt, nColors, targetFormat);
} else if (XCMS_DD_ID(format) && XCMS_DD_ID(targetFormat)) {
/*
* DD-to-DD only conversion
* Since DD->DD there will be no compressed thus we can
* pass NULL instead of pCompressed.
*/
retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors,
targetFormat, (Bool *)NULL);
} else {
/*
* Otherwise we have:
* 1. Device-Independent to Device-Dependent Conversion
* OR
* 2. Device-Dependent to Device-Independent Conversion
*
* We need to go from oldFormat -> CIEXYZ -> targetFormat
* adjusting for white points as necessary.
*/
if (XCMS_DI_ID(format)) {
/*
* 1. Device-Independent to Device-Dependent Conversion
*/
if (callWhiteAdjustProc) {
/*
* White Point Adjustment
* Client White Point to Screen White Point
*/
retval = (*ccc->whitePtAdjProc)(ccc, &clientWhitePt,
ScreenWhitePointOfCCC(ccc), targetFormat,
pColors_tmp, nColors, pCompressed);
} else {
if (_XcmsDIConvertColors(ccc, pColors_tmp,
&clientWhitePt, nColors, XcmsCIEXYZFormat)
== XcmsFailure) {
goto Failure;
}
retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors,
targetFormat, pCompressed);
}
} else {
/*
* 2. Device-Dependent to Device-Independent Conversion
*/
if (callWhiteAdjustProc) {
/*
* White Point Adjustment
* Screen White Point to Client White Point
*/
retval = (*ccc->whitePtAdjProc)(ccc,
ScreenWhitePointOfCCC(ccc), &clientWhitePt,
targetFormat, pColors_tmp, nColors, pCompressed);
} else {
/*
* Since DD->CIEXYZ, no compression takes place therefore
* we can pass NULL instead of pCompressed.
*/
if (_XcmsDDConvertColors(ccc, pColors_tmp, nColors,
XcmsCIEXYZFormat, (Bool *)NULL) == XcmsFailure) {
goto Failure;
}
retval = _XcmsDIConvertColors(ccc, pColors_tmp,
&clientWhitePt, nColors, targetFormat);
}
}
}
} else {
/*
* ARRAY HAS MIXED FORMATS.
*/
if ((contents_flag == (DI_FORMAT | MIX_FORMAT)) &&
XCMS_DI_ID(targetFormat)) {
/*
* Convert from DI to DI in batches of contiguous formats
*
* Because DI->DI, WhiteAdjustProc not called.
*/
retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
nColors, targetFormat, (unsigned char)DI_FORMAT);
} else if ((contents_flag == (DD_FORMAT | MIX_FORMAT)) &&
XCMS_DD_ID(targetFormat)) {
/*
* Convert from DD to DD in batches of contiguous formats
*
* Because DD->DD, WhiteAdjustProc not called.
*/
retval = ConvertMixedColors(ccc, pColors_tmp,
(XcmsColor *)NULL, nColors, targetFormat,
(unsigned char)DD_FORMAT);
} else if (XCMS_DI_ID(targetFormat)) {
/*
* We need to convert from DI-to-DI and DD-to-DI, therefore
* 1. convert DD specifications to CIEXYZ, then
* 2. convert all in batches to the target DI format.
*
* Note that ConvertMixedColors will call WhiteAdjustProc
* as necessary.
*/
/*
* Convert only DD specifications in batches of contiguous formats
* to CIEXYZ
*
* Since DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc
* if required.
*/
retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
nColors, XcmsCIEXYZFormat, (unsigned char)DD_FORMAT);
/*
* Because at this point we may have a mix of DI formats
* (e.g., CIEXYZ, CIELuv) we must convert the specs to the
* target DI format in batches of contiguous source formats.
*/
retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
nColors, targetFormat, (unsigned char)DI_FORMAT);
} else {
/*
* We need to convert from DI-to-DD and DD-to-DD, therefore
* 1. convert DI specifications to CIEXYZ, then
* 2. convert all to the DD target format.
*
* This allows white point adjustment and gamut compression
* to be applied to all the color specifications in one
* swoop if those functions do in fact modify the entire
* group of color specifications.
*/
/*
* Convert in batches to CIEXYZ
*
* If DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc
* if required.
*/
if ((retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
nColors, XcmsCIEXYZFormat,
(unsigned char)(DI_FORMAT | DD_FORMAT))) == XcmsFailure) {
goto Failure;
}
/*
* Convert all specifications (now in CIEXYZ format) to
* the target DD format.
* Since CIEXYZ->DD, compression MAY take place therefore
* we must pass pCompressed.
* Note that WhiteAdjustProc must be used if necessary.
*/
if (callWhiteAdjustProc) {
/*
* White Point Adjustment
* Client White Point to Screen White Point
*/
retval = (*ccc->whitePtAdjProc)(ccc,
&clientWhitePt, ScreenWhitePointOfCCC(ccc),
targetFormat, pColors_tmp, nColors, pCompressed);
} else {
retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors,
targetFormat, pCompressed);
}
}
}
if (retval != XcmsFailure) {
memcpy((char *)pColors_in_out, (char *)pColors_tmp,
nColors * sizeof(XcmsColor));
}
if (nColors > 1) {
Xfree((char *)pColors_tmp);
}
return(retval);
Failure:
if (nColors > 1) {
Xfree((char *)pColors_tmp);
}
return(XcmsFailure);
}
/*
* NAME
* XcmsRegFormatOfPrefix
*
* SYNOPSIS
*/
XcmsColorFormat
_XcmsRegFormatOfPrefix(
_Xconst char *prefix)
/*
* DESCRIPTION
* Returns a color space ID associated with the specified
* X Consortium registered color space prefix.
*
* RETURNS
* The color space ID if found;
* otherwise NULL.
*/
{
XcmsRegColorSpaceEntry *pEntry = _XcmsRegColorSpaces;
while (pEntry->prefix != NULL) {
if (strcmp(prefix, pEntry->prefix) == 0) {
return(pEntry->id);
}
pEntry++;
}
return(XcmsUndefinedFormat);
}
|
astrangeguy/libx11-debian-mirror
|
src/GetStCmap.c
|
/***********************************************************
Copyright 1987, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include "Xatomtype.h"
#include <X11/Xatom.h>
/*
* WARNING
*
* This is a pre-ICCCM routine. It must not reference any of the new fields
* in the XStandardColormap structure.
*/
Status XGetStandardColormap (
Display *dpy,
Window w,
XStandardColormap *cmap,
Atom property) /* XA_RGB_BEST_MAP, etc. */
{
Status stat; /* return value */
XStandardColormap *stdcmaps; /* will get malloced value */
int nstdcmaps; /* count of above */
stat = XGetRGBColormaps (dpy, w, &stdcmaps, &nstdcmaps, property);
if (stat) {
XStandardColormap *use;
if (nstdcmaps > 1) {
VisualID vid;
Screen *sp = _XScreenOfWindow (dpy, w);
int i;
if (!sp) {
if (stdcmaps) Xfree ((char *) stdcmaps);
return False;
}
vid = sp->root_visual->visualid;
for (i = 0; i < nstdcmaps; i++) {
if (stdcmaps[i].visualid == vid) break;
}
if (i == nstdcmaps) { /* not found */
Xfree ((char *) stdcmaps);
return False;
}
use = &stdcmaps[i];
} else {
use = stdcmaps;
}
/*
* assign only those fields which were in the pre-ICCCM version
*/
cmap->colormap = use->colormap;
cmap->red_max = use->red_max;
cmap->red_mult = use->red_mult;
cmap->green_max = use->green_max;
cmap->green_mult = use->green_mult;
cmap->blue_max = use->blue_max;
cmap->blue_mult = use->blue_mult;
cmap->base_pixel = use->base_pixel;
Xfree ((char *) stdcmaps); /* don't need alloced memory */
}
return stat;
}
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBCompat.c
|
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#define NEED_MAP_READERS
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include "XKBlibint.h"
Status
_XkbReadGetCompatMapReply( Display * dpy,
xkbGetCompatMapReply * rep,
XkbDescPtr xkb,
int * nread_rtrn)
{
register int i;
XkbReadBufferRec buf;
if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
return BadAlloc;
if (nread_rtrn)
*nread_rtrn= (int)rep->length*4;
i= rep->firstSI+rep->nSI;
if ((!xkb->compat)&&
(XkbAllocCompatMap(xkb,XkbAllCompatMask,i)!=Success))
return BadAlloc;
if (rep->nSI!=0) {
XkbSymInterpretRec *syms;
xkbSymInterpretWireDesc *wire;
wire= (xkbSymInterpretWireDesc *)_XkbGetReadBufferPtr(&buf,
rep->nSI*SIZEOF(xkbSymInterpretWireDesc));
if (wire==NULL)
goto BAILOUT;
syms= &xkb->compat->sym_interpret[rep->firstSI];
for (i=0;i<rep->nSI;i++,syms++,wire++) {
syms->sym= wire->sym;
syms->mods= wire->mods;
syms->match= wire->match;
syms->virtual_mod= wire->virtualMod;
syms->flags= wire->flags;
syms->act= *((XkbAnyAction *)&wire->act);
}
xkb->compat->num_si+= rep->nSI;
}
if (rep->groups&XkbAllGroupsMask) {
register unsigned bit,nGroups;
xkbModsWireDesc * wire;
for (i=0,nGroups=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if (rep->groups&bit)
nGroups++;
}
wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf,
nGroups*SIZEOF(xkbModsWireDesc));
if (wire==NULL)
goto BAILOUT;
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if ((rep->groups&bit)==0)
continue;
xkb->compat->groups[i].mask= wire->mask;
xkb->compat->groups[i].real_mods= wire->realMods;
xkb->compat->groups[i].vmods= wire->virtualMods;
wire++;
}
}
i= _XkbFreeReadBuffer(&buf);
if (i)
fprintf(stderr,"CompatMapReply! Bad length (%d extra bytes)\n",i);
if (i || buf.error)
return BadLength;
return Success;
BAILOUT:
_XkbFreeReadBuffer(&buf);
return BadLength;
}
Status
XkbGetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb)
{
register xkbGetCompatMapReq *req;
xkbGetCompatMapReply rep;
Status status;
XkbInfoPtr xkbi;
if ( (!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
((xkb->dpy!=NULL)&&(xkb->dpy!=dpy)) ||
(!dpy->xkb_info && (!XkbUseExtension(dpy,NULL,NULL))))
return BadAccess;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbGetCompatMap, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetCompatMap;
req->deviceSpec = xkb->device_spec;
if (which&XkbSymInterpMask)
req->getAllSI= True;
else req->getAllSI= False;
req->firstSI= req->nSI= 0;
if (which&XkbGroupCompatMask)
req->groups= XkbAllGroupsMask;
else req->groups= 0;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return BadLength;
}
if (xkb->dpy==NULL)
xkb->dpy= dpy;
if (xkb->device_spec==XkbUseCoreKbd)
xkb->device_spec= rep.deviceID;
status = _XkbReadGetCompatMapReply(dpy,&rep,xkb,NULL);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
static Bool
_XkbWriteSetCompatMap(Display *dpy,xkbSetCompatMapReq *req,XkbDescPtr xkb)
{
CARD16 firstSI;
CARD16 nSI;
int size;
register int i,nGroups;
register unsigned bit;
unsigned groups;
char * buf;
firstSI = req->firstSI;
nSI = req->nSI;
size= nSI*SIZEOF(xkbSymInterpretWireDesc);
nGroups= 0;
groups= req->groups;
if (groups&XkbAllGroupsMask) {
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if (groups&bit)
nGroups++;
}
size+= SIZEOF(xkbModsWireDesc)*nGroups;
}
req->length+= size/4;
BufAlloc(char *,buf,size);
if (!buf)
return False;
if (nSI) {
XkbSymInterpretPtr sym= &xkb->compat->sym_interpret[firstSI];
xkbSymInterpretWireDesc *wire= (xkbSymInterpretWireDesc *)buf;
for (i=0;i<nSI;i++,wire++,sym++) {
wire->sym= (CARD32)sym->sym;
wire->mods= sym->mods;
wire->match= sym->match;
wire->flags= sym->flags;
wire->virtualMod= sym->virtual_mod;
memcpy(&wire->act,&sym->act,sz_xkbActionWireDesc);
}
buf+= nSI*SIZEOF(xkbSymInterpretWireDesc);
}
if (groups&XkbAllGroupsMask) {
xkbModsWireDesc * out;
out= (xkbModsWireDesc *)buf;
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if ((groups&bit)!=0) {
out->mask= xkb->compat->groups[i].mask;
out->realMods= xkb->compat->groups[i].real_mods;
out->virtualMods= xkb->compat->groups[i].vmods;
out++;
}
}
buf+= nGroups*SIZEOF(xkbModsWireDesc);
}
return True;
}
Bool
XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions)
{
register xkbSetCompatMapReq *req;
Status ok;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || (dpy!=xkb->dpy) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
if ((!xkb->compat) ||
((which&XkbSymInterpMask)&&(!xkb->compat->sym_interpret)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbSetCompatMap, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSetCompatMap;
req->deviceSpec = xkb->device_spec;
req->recomputeActions = updateActions;
if (which&XkbSymInterpMask) {
req->truncateSI = True;
req->firstSI= 0;
req->nSI= xkb->compat->num_si;
}
else {
req->truncateSI = False;
req->firstSI= 0;
req->nSI= 0;
}
if (which&XkbGroupCompatMask)
req->groups= XkbAllGroupsMask;
else req->groups= 0;
ok= _XkbWriteSetCompatMap(dpy,req,xkb);
UnlockDisplay(dpy);
SyncHandle();
return ok;
}
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBBell.c
|
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include "XKBlibint.h"
Bool
XkbDeviceBell( Display * dpy,
Window window,
int deviceID,
int bellClass,
int bellID,
int percent,
Atom name)
{
register xkbBellReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbBell,req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbBell;
req->deviceSpec = deviceID;
req->window = (CARD32)window;
req->bellClass = (CARD16)bellClass;
req->bellID = (CARD16)bellID;
req->percent = percent;
req->forceSound = False;
req->eventOnly = False;
req->pitch = 0;
req->duration = 0;
req->name = (CARD32)name;
req->pad1= 0; req->pad2= 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbForceDeviceBell( Display * dpy,
int deviceID,
int bellClass,
int bellID,
int percent)
{
register xkbBellReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbBell,req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbBell;
req->deviceSpec = deviceID;
req->window = (CARD32)None;
req->bellClass = (CARD16)bellClass;
req->bellID = (CARD16)bellID;
req->percent = percent;
req->forceSound = True;
req->eventOnly = False;
req->pitch = 0;
req->duration = 0;
req->name = None;
req->pad1= 0; req->pad2= 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbDeviceBellEvent( Display * dpy,
Window window,
int deviceID,
int bellClass,
int bellID,
int percent,
Atom name)
{
register xkbBellReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbBell,req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbBell;
req->deviceSpec = deviceID;
req->window = (CARD32)window;
req->bellClass = (CARD16)bellClass;
req->bellID = (CARD16)bellID;
req->percent = percent;
req->forceSound = False;
req->eventOnly = True;
req->pitch = 0;
req->duration = 0;
req->name = (CARD32)name;
req->pad1= 0; req->pad2= 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbBell(Display *dpy,Window window,int percent,Atom name)
{
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
XBell(dpy,percent);
return False;
}
return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
percent,name);
}
Bool
XkbForceBell(Display *dpy,int percent)
{
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
XBell(dpy,percent);
return False;
}
return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
percent);
}
Bool
XkbBellEvent(Display *dpy,Window window,int percent,Atom name)
{
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
return False;
}
/* class 0 = KbdFeedbackClass (X Input Extension) */
return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd,
XkbDfltXIClass,XkbDfltXIId,
percent,name);
}
|
astrangeguy/libx11-debian-mirror
|
src/GetWAttrs.c
|
/*
Copyright 1986, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
typedef struct _WAttrsState {
unsigned long attr_seq;
unsigned long geom_seq;
XWindowAttributes *attr;
} _XWAttrsState;
static Bool
_XWAttrsHandler(
register Display *dpy,
register xReply *rep,
char *buf,
int len,
XPointer data)
{
register _XWAttrsState *state;
xGetWindowAttributesReply replbuf;
register xGetWindowAttributesReply *repl;
register XWindowAttributes *attr;
state = (_XWAttrsState *)data;
if (dpy->last_request_read != state->attr_seq) {
if (dpy->last_request_read == state->geom_seq &&
!state->attr &&
rep->generic.type == X_Error &&
rep->error.errorCode == BadDrawable)
return True;
return False;
}
if (rep->generic.type == X_Error) {
state->attr = (XWindowAttributes *)NULL;
return False;
}
repl = (xGetWindowAttributesReply *)
_XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
(SIZEOF(xGetWindowAttributesReply) - SIZEOF(xReply)) >> 2,
True);
attr = state->attr;
attr->class = repl->class;
attr->bit_gravity = repl->bitGravity;
attr->win_gravity = repl->winGravity;
attr->backing_store = repl->backingStore;
attr->backing_planes = repl->backingBitPlanes;
attr->backing_pixel = repl->backingPixel;
attr->save_under = repl->saveUnder;
attr->colormap = repl->colormap;
attr->map_installed = repl->mapInstalled;
attr->map_state = repl->mapState;
attr->all_event_masks = repl->allEventMasks;
attr->your_event_mask = repl->yourEventMask;
attr->do_not_propagate_mask = repl->doNotPropagateMask;
attr->override_redirect = repl->override;
attr->visual = _XVIDtoVisual (dpy, repl->visualID);
return True;
}
Status
_XGetWindowAttributes(
register Display *dpy,
Window w,
XWindowAttributes *attr)
{
xGetGeometryReply rep;
register xResourceReq *req;
register int i;
register Screen *sp;
_XAsyncHandler async;
_XWAttrsState async_state;
GetResReq(GetWindowAttributes, w, req);
async_state.attr_seq = dpy->request;
async_state.geom_seq = 0;
async_state.attr = attr;
async.next = dpy->async_handlers;
async.handler = _XWAttrsHandler;
async.data = (XPointer)&async_state;
dpy->async_handlers = &async;
GetResReq(GetGeometry, w, req);
async_state.geom_seq = dpy->request;
if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
DeqAsyncHandler(dpy, &async);
return (0);
}
DeqAsyncHandler(dpy, &async);
if (!async_state.attr) {
return (0);
}
attr->x = cvtINT16toInt (rep.x);
attr->y = cvtINT16toInt (rep.y);
attr->width = rep.width;
attr->height = rep.height;
attr->border_width = rep.borderWidth;
attr->depth = rep.depth;
attr->root = rep.root;
/* find correct screen so that applications find it easier.... */
for (i = 0; i < dpy->nscreens; i++) {
sp = &dpy->screens[i];
if (sp->root == attr->root) {
attr->screen = sp;
break;
}
}
return(1);
}
Status
XGetWindowAttributes(
Display *dpy,
Window w,
XWindowAttributes *attr)
{
Status ret;
LockDisplay(dpy);
ret = _XGetWindowAttributes(dpy, w, attr);
UnlockDisplay(dpy);
SyncHandle();
return ret;
}
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBGetMap.c
|
<gh_stars>0
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#define NEED_MAP_READERS
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include "XKBlibint.h"
static Status
_XkbReadKeyTypes(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
{
int i,n,lastMapCount;
XkbKeyTypePtr type;
if ( rep->nTypes>0 ) {
n = rep->firstType+rep->nTypes;
if (xkb->map->num_types>=n)
n= xkb->map->num_types;
else if (XkbAllocClientMap(xkb,XkbKeyTypesMask,n)!=Success)
return BadAlloc;
type = &xkb->map->types[rep->firstType];
for (i=0;i<(int)rep->nTypes;i++,type++) {
xkbKeyTypeWireDesc *desc;
register int ndx;
ndx= i+rep->firstType;
if (ndx>=xkb->map->num_types)
xkb->map->num_types= ndx+1;
desc= (xkbKeyTypeWireDesc *)_XkbGetReadBufferPtr(buf,
SIZEOF(xkbKeyTypeWireDesc));
if (desc==NULL)
return BadLength;
lastMapCount= type->map_count;
if ( desc->nMapEntries>0 ) {
if ((type->map==NULL)||(desc->nMapEntries>type->map_count)) {
XkbKTMapEntryRec *prev_map = type->map;
type->map= _XkbTypedRealloc(type->map,desc->nMapEntries,
XkbKTMapEntryRec);
if (type->map==NULL) {
_XkbFree(prev_map);
return BadAlloc;
}
}
}
else if (type->map!=NULL) {
Xfree(type->map);
type->map_count= 0;
type->map= NULL;
}
if ( desc->preserve && (desc->nMapEntries>0) ) {
if ((!type->preserve)||
(desc->nMapEntries>lastMapCount)) {
XkbModsRec *prev_preserve = type->preserve;
type->preserve= _XkbTypedRealloc(type->preserve,
desc->nMapEntries,
XkbModsRec);
if (type->preserve==NULL) {
_XkbFree(prev_preserve);
return BadAlloc;
}
}
}
else if (type->preserve!=NULL) {
Xfree(type->preserve);
type->preserve= NULL;
}
type->mods.mask = desc->mask;
type->mods.real_mods = desc->realMods;
type->mods.vmods = desc->virtualMods;
type->num_levels = desc->numLevels;
type->map_count = desc->nMapEntries;
if (desc->nMapEntries>0) {
register xkbKTMapEntryWireDesc *wire;
register XkbKTMapEntryPtr entry;
register int size;
size= type->map_count*SIZEOF(xkbKTMapEntryWireDesc);
wire= (xkbKTMapEntryWireDesc *)_XkbGetReadBufferPtr(buf,size);
if (wire==NULL)
return BadLength;
entry= type->map;
for (n=0;n<type->map_count;n++,wire++,entry++) {
entry->active= wire->active;
entry->level= wire->level;
entry->mods.mask= wire->mask;
entry->mods.real_mods= wire->realMods;
entry->mods.vmods= wire->virtualMods;
}
if (desc->preserve) {
register xkbModsWireDesc * pwire;
register XkbModsPtr preserve;
register int sz;
sz= desc->nMapEntries*SIZEOF(xkbModsWireDesc);
pwire=(xkbModsWireDesc *)_XkbGetReadBufferPtr(buf,sz);
if (pwire==NULL)
return BadLength;
preserve= type->preserve;
for (n=0;n<desc->nMapEntries;n++,pwire++,preserve++) {
preserve->mask= pwire->mask;
preserve->vmods= pwire->virtualMods;
preserve->real_mods= pwire->realMods;
}
}
}
}
}
return Success;
}
static Status
_XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
{
register int i;
XkbClientMapPtr map;
map= xkb->map;
if (map->key_sym_map==NULL) {
register int offset;
XkbSymMapPtr oldMap;
xkbSymMapWireDesc *newMap;
map->key_sym_map= _XkbTypedCalloc((xkb->max_key_code+1),XkbSymMapRec);
if (map->key_sym_map==NULL)
return BadAlloc;
if (map->syms==NULL) {
int sz;
sz= (rep->totalSyms*12)/10;
sz= ((sz+(unsigned)128)/128)*128;
map->syms = _XkbTypedCalloc(sz,KeySym);
if (map->syms==NULL)
return BadAlloc;
map->size_syms = sz;
}
offset = 1;
oldMap = &map->key_sym_map[rep->firstKeySym];
for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
newMap= (xkbSymMapWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc));
if (newMap==NULL)
return BadLength;
oldMap->kt_index[0]= newMap->ktIndex[0];
oldMap->kt_index[1]= newMap->ktIndex[1];
oldMap->kt_index[2]= newMap->ktIndex[2];
oldMap->kt_index[3]= newMap->ktIndex[3];
oldMap->group_info= newMap->groupInfo;
oldMap->width= newMap->width;
oldMap->offset= offset;
if (offset+newMap->nSyms>=map->size_syms) {
register int sz;
KeySym *prev_syms = map->syms;
sz= map->size_syms+128;
map->syms= _XkbTypedRealloc(map->syms,sz,KeySym);
if (map->syms==NULL) {
_XkbFree(prev_syms);
map->size_syms= 0;
return BadAlloc;
}
map->size_syms= sz;
}
if (newMap->nSyms>0) {
_XkbReadBufferCopyKeySyms(buf,(KeySym *)&map->syms[offset],
newMap->nSyms);
offset+= newMap->nSyms;
}
else {
map->syms[offset]= 0;
}
}
map->num_syms= offset;
}
else {
xkbSymMapWireDesc * newMap;
XkbSymMapPtr oldMap;
KeySym * newSyms;
int tmp;
oldMap = &map->key_sym_map[rep->firstKeySym];
for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) {
newMap= (xkbSymMapWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc));
if (newMap==NULL)
return BadLength;
if (newMap->nSyms>0)
tmp= newMap->nSyms;
else tmp= 0;
newSyms = XkbResizeKeySyms(xkb,i+rep->firstKeySym,tmp);
if (newSyms==NULL)
return BadAlloc;
if (newMap->nSyms>0)
_XkbReadBufferCopyKeySyms(buf,newSyms,newMap->nSyms);
else newSyms[0]= NoSymbol;
oldMap->kt_index[0] = newMap->ktIndex[0];
oldMap->kt_index[1] = newMap->ktIndex[1];
oldMap->kt_index[2] = newMap->ktIndex[2];
oldMap->kt_index[3] = newMap->ktIndex[3];
oldMap->group_info = newMap->groupInfo;
oldMap->width = newMap->width;
}
}
return Success;
}
static Status
_XkbReadKeyActions(XkbReadBufferPtr buf,XkbDescPtr info,xkbGetMapReply *rep)
{
int i;
CARD8 numDescBuf[248];
CARD8* numDesc = NULL;
register int nKeyActs;
Status ret = Success;
if ( (nKeyActs=rep->nKeyActs)>0 ) {
XkbSymMapPtr symMap;
if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf;
else numDesc = Xmalloc (nKeyActs * sizeof(CARD8));
if (!_XkbCopyFromReadBuffer(buf, (char *)numDesc, nKeyActs)) {
ret = BadLength;
goto done;
}
i= XkbPaddedSize(nKeyActs)-nKeyActs;
if ((i>0)&&(!_XkbSkipReadBufferData(buf,i))) {
ret = BadLength;
goto done;
}
symMap = &info->map->key_sym_map[rep->firstKeyAct];
for (i=0;i<(int)rep->nKeyActs;i++,symMap++) {
if (numDesc[i]==0) {
info->server->key_acts[i+rep->firstKeyAct]= 0;
}
else {
XkbAction *newActs;
/* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */
/* either zero or XkbKeyNumSyms(info,key) */
newActs=XkbResizeKeyActions(info,i+rep->firstKeyAct,
numDesc[i]);
if (newActs==NULL) {
ret = BadAlloc;
goto done;
}
if (!_XkbCopyFromReadBuffer(buf,(char *)newActs,
(int)(numDesc[i]*sizeof(XkbAction)))) {
ret = BadLength;
goto done;
}
}
}
}
done:
if (numDesc != NULL && numDesc != numDescBuf) Xfree (numDesc);
return ret;
}
static Status
_XkbReadKeyBehaviors(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
{
register int i;
xkbBehaviorWireDesc *wire;
if ( rep->totalKeyBehaviors>0 ) {
if ( xkb->server->behaviors == NULL ) {
int size = xkb->max_key_code+1;
xkb->server->behaviors = _XkbTypedCalloc(size,XkbBehavior);
if (xkb->server->behaviors==NULL)
return BadAlloc;
}
else {
bzero(&xkb->server->behaviors[rep->firstKeyBehavior],
(rep->nKeyBehaviors*sizeof(XkbBehavior)));
}
for (i=0;i<rep->totalKeyBehaviors;i++) {
wire= (xkbBehaviorWireDesc *)_XkbGetReadBufferPtr(buf,
SIZEOF(xkbBehaviorWireDesc));
if (wire==NULL)
return BadLength;
xkb->server->behaviors[wire->key].type= wire->type;
xkb->server->behaviors[wire->key].data= wire->data;
}
}
return Success;
}
static Status
_XkbReadVirtualMods(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
{
if ( rep->virtualMods ) {
register int i,bit,nVMods;
register char *data;
for (i=nVMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
if (rep->virtualMods&bit)
nVMods++;
}
data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods));
if (data==NULL)
return BadLength;
for (i=0,bit=1;(i<XkbNumVirtualMods)&&(nVMods>0);i++,bit<<=1) {
if (rep->virtualMods&bit) {
xkb->server->vmods[i]= *data++;
nVMods--;
}
}
}
return Success;
}
static Status
_XkbReadExplicitComponents( XkbReadBufferPtr buf,
XkbDescPtr xkb,
xkbGetMapReply * rep)
{
register int i;
unsigned char *wire;
if ( rep->totalKeyExplicit>0 ) {
if ( xkb->server->explicit == NULL ) {
int size = xkb->max_key_code+1;
xkb->server->explicit = _XkbTypedCalloc(size,unsigned char);
if (xkb->server->explicit==NULL)
return BadAlloc;
}
else {
bzero(&xkb->server->explicit[rep->firstKeyExplicit],
rep->nKeyExplicit);
}
i= XkbPaddedSize(2*rep->totalKeyExplicit);
wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
if (!wire)
return BadLength;
for (i=0;i<rep->totalKeyExplicit;i++,wire+=2) {
xkb->server->explicit[wire[0]]= wire[1];
}
}
return Success;
}
static Status
_XkbReadModifierMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
{
register int i;
unsigned char *wire;
if ( rep->totalModMapKeys>0 ) {
if ((xkb->map->modmap==NULL)&&
(XkbAllocClientMap(xkb,XkbModifierMapMask,0)!=Success)) {
return BadAlloc;
}
else {
bzero(&xkb->map->modmap[rep->firstModMapKey],rep->nModMapKeys);
}
i= XkbPaddedSize(2*rep->totalModMapKeys);
wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i);
if (!wire)
return BadLength;
for (i=0;i<rep->totalModMapKeys;i++,wire+=2) {
xkb->map->modmap[wire[0]]= wire[1];
}
}
return Success;
}
static Status
_XkbReadVirtualModMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
{
register int i;
xkbVModMapWireDesc * wire;
XkbServerMapPtr srv;
if ( rep->totalVModMapKeys>0 ) {
if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&&
(XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) {
return BadAlloc;
}
else {
srv= xkb->server;
if (rep->nVModMapKeys > rep->firstVModMapKey)
bzero((char *)&srv->vmodmap[rep->firstVModMapKey],
(rep->nVModMapKeys - rep->firstVModMapKey) *
sizeof(unsigned short));
}
srv= xkb->server;
i= rep->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc);
wire=(xkbVModMapWireDesc *)_XkbGetReadBufferPtr(buf,i);
if (!wire)
return BadLength;
for (i=0;i<rep->totalVModMapKeys;i++,wire++) {
if ((wire->key>=xkb->min_key_code)&&(wire->key<=xkb->max_key_code))
srv->vmodmap[wire->key]= wire->vmods;
}
}
return Success;
}
static xkbGetMapReq *
_XkbGetGetMapReq(Display *dpy,XkbDescPtr xkb)
{
xkbGetMapReq *req;
GetReq(kbGetMap, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetMap;
req->deviceSpec = xkb->device_spec;
req->full = req->partial = 0;
req->firstType = req->nTypes = 0;
req->firstKeySym = req->nKeySyms = 0;
req->firstKeyAct = req->nKeyActs = 0;
req->firstKeyBehavior = req->nKeyBehaviors = 0;
req->virtualMods = 0;
req->firstKeyExplicit = req->nKeyExplicit = 0;
req->firstModMapKey = req->nModMapKeys = 0;
req->firstVModMapKey = req->nVModMapKeys = 0;
return req;
}
Status
_XkbReadGetMapReply( Display * dpy,
xkbGetMapReply *rep,
XkbDescPtr xkb,
int * nread_rtrn)
{
int extraData;
unsigned mask;
if ( xkb->device_spec == XkbUseCoreKbd )
xkb->device_spec= rep->deviceID;
xkb->min_key_code = rep->minKeyCode;
xkb->max_key_code = rep->maxKeyCode;
if (!xkb->map) {
mask= rep->present&XkbAllClientInfoMask;
if (mask&&(XkbAllocClientMap(xkb,mask,rep->nTypes)!=Success))
return BadAlloc;
}
if (!xkb->server) {
mask= rep->present&XkbAllServerInfoMask;
if (mask&&(XkbAllocServerMap(xkb,mask,rep->totalActs)!=Success))
return BadAlloc;
}
extraData= (int)(rep->length*4);
extraData-= (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply));
if (rep->length) {
XkbReadBufferRec buf;
int left;
if (_XkbInitReadBuffer(dpy,&buf,extraData)) {
Status status= Success;
if (nread_rtrn!=NULL)
*nread_rtrn= extraData;
if (status==Success)
status= _XkbReadKeyTypes(&buf,xkb,rep);
if (status==Success)
status= _XkbReadKeySyms(&buf,xkb,rep);
if (status==Success)
status= _XkbReadKeyActions(&buf,xkb,rep);
if (status==Success)
status= _XkbReadKeyBehaviors(&buf,xkb,rep);
if (status==Success)
status= _XkbReadVirtualMods(&buf,xkb,rep);
if (status==Success)
status= _XkbReadExplicitComponents(&buf,xkb,rep);
if (status==Success)
status= _XkbReadModifierMap(&buf,xkb,rep);
if (status==Success)
status= _XkbReadVirtualModMap(&buf,xkb,rep);
left= _XkbFreeReadBuffer(&buf);
if (status!=Success) return status;
else if ( left || buf.error ) return BadLength;
}
else return BadAlloc;
}
return Success;
}
static Status
_XkbHandleGetMapReply(Display *dpy,XkbDescPtr xkb)
{
xkbGetMapReply rep;
if (!_XReply(dpy, (xReply *)&rep,
( (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)) >> 2 ),
xFalse)) {
return BadImplementation;
}
return _XkbReadGetMapReply(dpy,&rep,xkb,NULL);
}
Status
XkbGetUpdatedMap(Display *dpy,unsigned which,XkbDescPtr xkb)
{
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if (which) {
register xkbGetMapReq *req;
Status status;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->full = which;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
return Success;
}
XkbDescPtr
XkbGetMap(Display *dpy,unsigned which,unsigned deviceSpec)
{
XkbDescPtr xkb;
xkb = _XkbTypedCalloc(1,XkbDescRec);
if (xkb) {
xkb->device_spec = deviceSpec;
xkb->map = _XkbTypedCalloc(1,XkbClientMapRec);
if ((xkb->map==NULL)||
((which)&&(XkbGetUpdatedMap(dpy,which,xkb)!=Success))) {
if (xkb->map) {
Xfree(xkb->map);
xkb->map= NULL;
}
Xfree(xkb);
return NULL;
}
xkb->dpy= dpy;
}
return xkb;
}
Status
XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyTypes))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstType = first;
req->nTypes = num;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeyAct = first;
req->nKeyActs = num;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeySym = first;
req->nKeySyms = num;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeyBehavior = first;
req->nKeyBehaviors = num;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->virtualMods = which;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetKeyExplicitComponents( Display * dpy,
unsigned first,
unsigned num,
XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeyExplicit = first;
req->nKeyExplicit = num;
if ((xkb!=NULL) && (xkb->server!=NULL) && (xkb->server->explicit!=NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
bzero(&xkb->server->explicit[first],num);
}
if (xkb)
status= _XkbHandleGetMapReply(dpy, xkb);
else
status = BadMatch;
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstModMapKey = first;
req->nModMapKeys = num;
if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
bzero(&xkb->map->modmap[first],num);
}
if (xkb)
status= _XkbHandleGetMapReply(dpy, xkb);
else
status = BadMatch;
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
{
register xkbGetMapReq *req;
Status status;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount))
return BadValue;
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
req->firstVModMapKey = first;
req->nVModMapKeys = num;
if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short));
}
if (xkb)
status= _XkbHandleGetMapReply(dpy, xkb);
else
status = BadMatch;
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetMapChanges(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes)
{
xkbGetMapReq *req;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
LockDisplay(dpy);
if (changes->changed) {
Status status= Success;
req = _XkbGetGetMapReq(dpy, xkb);
req->full = 0;
req->partial = changes->changed;
req->firstType = changes->first_type;
req->nTypes = changes->num_types;
req->firstKeySym = changes->first_key_sym;
req->nKeySyms = changes->num_key_syms;
req->firstKeyAct = changes->first_key_act;
req->nKeyActs = changes->num_key_acts;
req->firstKeyBehavior = changes->first_key_behavior;
req->nKeyBehaviors = changes->num_key_behaviors;
req->virtualMods = changes->vmods;
req->firstKeyExplicit = changes->first_key_explicit;
req->nKeyExplicit = changes->num_key_explicit;
req->firstModMapKey = changes->first_modmap_key;
req->nModMapKeys = changes->num_modmap_keys;
req->firstVModMapKey = changes->first_vmodmap_key;
req->nVModMapKeys = changes->num_vmodmap_keys;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
UnlockDisplay(dpy);
return Success;
}
|
astrangeguy/libx11-debian-mirror
|
modules/im/ximcp/imLcPrs.c
|
<filename>modules/im/ximcp/imLcPrs.c
/******************************************************************
Copyright 1992 by Oki Technosystems Laboratory, Inc.
Copyright 1992 by Fuji Xerox Co., Ltd.
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation, and that the name of Oki Technosystems
Laboratory and Fuji Xerox not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.
Oki Technosystems Laboratory and Fuji Xerox make no representations
about the suitability of this software for any purpose. It is provided
"as is" without express or implied warranty.
OKI TECHNOSYSTEMS LABORATORY AND FUJI XEROX DISCLAIM ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OKI TECHNOSYSTEMS
LABORATORY AND FUJI XEROX BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
OR PERFORMANCE OF THIS SOFTWARE.
Author: <NAME> Oki Technosystems Laboratory
Author: <NAME> <NAME>
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xmd.h>
#include <X11/Xos.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "Ximint.h"
#include <sys/stat.h>
#include <stdio.h>
#define XLC_BUFSIZE 256
extern int _Xmbstowcs(
wchar_t *wstr,
char *str,
int len
);
extern int _Xmbstoutf8(
char *ustr,
const char *str,
int len
);
/*
* Parsing File Format:
*
* FILE ::= { [PRODUCTION] [COMMENT] "\n"}
* PRODUCTION ::= LHS ":" RHS [ COMMENT ]
* COMMENT ::= "#" {<any character except null or newline>}
* LHS ::= EVENT { EVENT }
* EVENT ::= [MODIFIER_LIST] "<" keysym ">"
* MODIFIER_LIST ::= ("!" {MODIFIER} ) | "None"
* MODIFIER ::= ["~"] modifier_name
* RHS ::= ( STRING | keysym | STRING keysym )
* STRING ::= '"' { CHAR } '"'
* CHAR ::= GRAPHIC_CHAR | ESCAPED_CHAR
* GRAPHIC_CHAR ::= locale (codeset) dependent code
* ESCAPED_CHAR ::= ('\\' | '\"' | OCTAL | HEX )
* OCTAL ::= '\' OCTAL_CHAR [OCTAL_CHAR [OCTAL_CHAR]]
* OCTAL_CHAR ::= (0|1|2|3|4|5|6|7)
* HEX ::= '\' (x|X) HEX_CHAR [HEX_CHAR]]
* HEX_CHAR ::= (0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|a|b|c|d|e|f)
*
*/
static int
nextch(
FILE *fp,
int *lastch)
{
int c;
if (*lastch != 0) {
c = *lastch;
*lastch = 0;
} else {
c = getc(fp);
if (c == '\\') {
c = getc(fp);
if (c == '\n') {
c = getc(fp);
} else {
ungetc(c, fp);
c = '\\';
}
}
}
return(c);
}
static void
putbackch(
int c,
int *lastch)
{
*lastch = c;
}
#define ENDOFFILE 0
#define ENDOFLINE 1
#define COLON 2
#define LESS 3
#define GREATER 4
#define EXCLAM 5
#define TILDE 6
#define STRING 7
#define KEY 8
#define ERROR 9
#ifndef isalnum
#define isalnum(c) \
(('0' <= (c) && (c) <= '9') || \
('A' <= (c) && (c) <= 'Z') || \
('a' <= (c) && (c) <= 'z'))
#endif
static int
nexttoken(
FILE *fp,
char *tokenbuf,
int *lastch)
{
int c;
int token;
char *p;
int i, j;
while ((c = nextch(fp, lastch)) == ' ' || c == '\t') {
}
switch (c) {
case EOF:
token = ENDOFFILE;
break;
case '\n':
token = ENDOFLINE;
break;
case '<':
token = LESS;
break;
case '>':
token = GREATER;
break;
case ':':
token = COLON;
break;
case '!':
token = EXCLAM;
break;
case '~':
token = TILDE;
break;
case '"':
p = tokenbuf;
while ((c = nextch(fp, lastch)) != '"') {
if (c == '\n' || c == EOF) {
putbackch(c, lastch);
token = ERROR;
goto string_error;
} else if (c == '\\') {
c = nextch(fp, lastch);
switch (c) {
case '\\':
case '"':
*p++ = c;
break;
case 'n':
*p++ = '\n';
break;
case 'r':
*p++ = '\r';
break;
case 't':
*p++ = '\t';
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
i = c - '0';
c = nextch(fp, lastch);
for (j = 0; j < 2 && c >= '0' && c <= '7'; j++) {
i <<= 3;
i += c - '0';
c = nextch(fp, lastch);
}
putbackch(c, lastch);
*p++ = (char)i;
break;
case 'X':
case 'x':
i = 0;
for (j = 0; j < 2; j++) {
c = nextch(fp, lastch);
i <<= 4;
if (c >= '0' && c <= '9') {
i += c - '0';
} else if (c >= 'A' && c <= 'F') {
i += c - 'A' + 10;
} else if (c >= 'a' && c <= 'f') {
i += c - 'a' + 10;
} else {
putbackch(c, lastch);
i >>= 4;
break;
}
}
if (j == 0) {
token = ERROR;
goto string_error;
}
*p++ = (char)i;
break;
case EOF:
putbackch(c, lastch);
token = ERROR;
goto string_error;
default:
*p++ = c;
break;
}
} else {
*p++ = c;
}
}
*p = '\0';
token = STRING;
break;
case '#':
while ((c = nextch(fp, lastch)) != '\n' && c != EOF) {
}
if (c == '\n') {
token = ENDOFLINE;
} else {
token = ENDOFFILE;
}
break;
default:
if (isalnum(c) || c == '_' || c == '-') {
p = tokenbuf;
*p++ = c;
c = nextch(fp, lastch);
while (isalnum(c) || c == '_' || c == '-') {
*p++ = c;
c = nextch(fp, lastch);
}
*p = '\0';
putbackch(c, lastch);
token = KEY;
} else {
token = ERROR;
}
break;
}
string_error:
return(token);
}
static long
modmask(
char *name)
{
struct _modtbl {
const char name[6];
long mask;
};
static const struct _modtbl tbl[] = {
{ "Ctrl", ControlMask },
{ "Lock", LockMask },
{ "Caps", LockMask },
{ "Shift", ShiftMask },
{ "Alt", Mod1Mask },
{ "Meta", Mod1Mask }};
int i, num_entries = sizeof (tbl) / sizeof (tbl[0]);
for (i = 0; i < num_entries; i++)
if (!strcmp (name, tbl[i].name))
return tbl[i].mask;
return 0;
}
static char*
TransFileName(Xim im, char *name)
{
char *home = NULL, *lcCompose = NULL;
char dir[XLC_BUFSIZE];
char *i = name, *ret, *j;
int l = 0;
while (*i) {
if (*i == '%') {
i++;
switch (*i) {
case '%':
l++;
break;
case 'H':
home = getenv("HOME");
if (home)
l += strlen(home);
break;
case 'L':
if (lcCompose == NULL)
lcCompose = _XlcFileName(im->core.lcd, COMPOSE_FILE);
if (lcCompose)
l += strlen(lcCompose);
break;
case 'S':
xlocaledir(dir, XLC_BUFSIZE);
l += strlen(dir);
break;
}
} else {
l++;
}
i++;
}
j = ret = Xmalloc(l+1);
if (ret == NULL)
return ret;
i = name;
while (*i) {
if (*i == '%') {
i++;
switch (*i) {
case '%':
*j++ = '%';
break;
case 'H':
if (home) {
strcpy(j, home);
j += strlen(home);
}
break;
case 'L':
if (lcCompose) {
strcpy(j, lcCompose);
j += strlen(lcCompose);
}
break;
case 'S':
strcpy(j, dir);
j += strlen(dir);
break;
}
i++;
} else {
*j++ = *i++;
}
}
*j = '\0';
Xfree(lcCompose);
return ret;
}
#ifndef MB_LEN_MAX
#define MB_LEN_MAX 6
#endif
static int
get_mb_string (Xim im, char *buf, KeySym ks)
{
XPointer from, to;
int from_len, to_len, len;
XPointer args[1];
XlcCharSet charset;
char local_buf[MB_LEN_MAX];
unsigned int ucs;
ucs = KeySymToUcs4(ks);
from = (XPointer) &ucs;
to = (XPointer) local_buf;
from_len = 1;
to_len = MB_LEN_MAX;
args[0] = (XPointer) &charset;
if (_XlcConvert(im->private.local.ucstoc_conv,
&from, &from_len, &to, &to_len, args, 1 ) != 0) {
return 0;
}
from = (XPointer) local_buf;
to = (XPointer) buf;
from_len = MB_LEN_MAX - to_len;
to_len = MB_LEN_MAX + 1;
args[0] = (XPointer) charset;
if (_XlcConvert(im->private.local.cstomb_conv,
&from, &from_len, &to, &to_len, args, 1 ) != 0) {
return 0;
}
len = MB_LEN_MAX + 1 - to_len;
buf[len] = '\0';
return len;
}
#define AllMask (ShiftMask | LockMask | ControlMask | Mod1Mask)
#define LOCAL_WC_BUFSIZE 128
#define LOCAL_UTF8_BUFSIZE 256
#define SEQUENCE_MAX 10
static int
parseline(
FILE *fp,
Xim im,
char* tokenbuf)
{
int token;
DTModifier modifier_mask;
DTModifier modifier;
DTModifier tmp;
KeySym keysym = NoSymbol;
DTIndex *top = &im->private.local.top;
DefTreeBase *b = &im->private.local.base;
DTIndex t;
DefTree *p = NULL;
Bool exclam, tilde;
KeySym rhs_keysym = 0;
char *rhs_string_mb;
int l;
int lastch = 0;
char local_mb_buf[MB_LEN_MAX+1];
wchar_t local_wc_buf[LOCAL_WC_BUFSIZE], *rhs_string_wc;
char local_utf8_buf[LOCAL_UTF8_BUFSIZE], *rhs_string_utf8;
struct DefBuffer {
DTModifier modifier_mask;
DTModifier modifier;
KeySym keysym;
};
struct DefBuffer buf[SEQUENCE_MAX];
int i, n;
do {
token = nexttoken(fp, tokenbuf, &lastch);
} while (token == ENDOFLINE);
if (token == ENDOFFILE) {
return(-1);
}
n = 0;
do {
if ((token == KEY) && (strcmp("include", tokenbuf) == 0)) {
char *filename;
FILE *infp;
token = nexttoken(fp, tokenbuf, &lastch);
if (token != KEY && token != STRING)
goto error;
if ((filename = TransFileName(im, tokenbuf)) == NULL)
goto error;
infp = _XFopenFile(filename, "r");
Xfree(filename);
if (infp == NULL)
goto error;
_XimParseStringFile(infp, im);
fclose(infp);
return (0);
} else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
modifier = 0;
modifier_mask = AllMask;
token = nexttoken(fp, tokenbuf, &lastch);
} else {
modifier_mask = modifier = 0;
exclam = False;
if (token == EXCLAM) {
exclam = True;
token = nexttoken(fp, tokenbuf, &lastch);
}
while (token == TILDE || token == KEY) {
tilde = False;
if (token == TILDE) {
tilde = True;
token = nexttoken(fp, tokenbuf, &lastch);
if (token != KEY)
goto error;
}
tmp = modmask(tokenbuf);
if (!tmp) {
goto error;
}
modifier_mask |= tmp;
if (tilde) {
modifier &= ~tmp;
} else {
modifier |= tmp;
}
token = nexttoken(fp, tokenbuf, &lastch);
}
if (exclam) {
modifier_mask = AllMask;
}
}
if (token != LESS) {
goto error;
}
token = nexttoken(fp, tokenbuf, &lastch);
if (token != KEY) {
goto error;
}
token = nexttoken(fp, tokenbuf, &lastch);
if (token != GREATER) {
goto error;
}
keysym = XStringToKeysym(tokenbuf);
if (keysym == NoSymbol) {
goto error;
}
buf[n].keysym = keysym;
buf[n].modifier = modifier;
buf[n].modifier_mask = modifier_mask;
n++;
if( n >= SEQUENCE_MAX )
goto error;
token = nexttoken(fp, tokenbuf, &lastch);
} while (token != COLON);
token = nexttoken(fp, tokenbuf, &lastch);
if (token == STRING) {
l = strlen(tokenbuf) + 1;
while (b->mbused + l > b->mbsize) {
b->mbsize = b->mbsize ? b->mbsize * 1.5 : 1024;
if (! (b->mb = Xrealloc (b->mb, b->mbsize)) )
goto error;
}
rhs_string_mb = &b->mb[b->mbused];
b->mbused += l;
strcpy(rhs_string_mb, tokenbuf);
token = nexttoken(fp, tokenbuf, &lastch);
if (token == KEY) {
rhs_keysym = XStringToKeysym(tokenbuf);
if (rhs_keysym == NoSymbol) {
goto error;
}
token = nexttoken(fp, tokenbuf, &lastch);
}
if (token != ENDOFLINE && token != ENDOFFILE) {
goto error;
}
} else if (token == KEY) {
rhs_keysym = XStringToKeysym(tokenbuf);
if (rhs_keysym == NoSymbol) {
goto error;
}
token = nexttoken(fp, tokenbuf, &lastch);
if (token != ENDOFLINE && token != ENDOFFILE) {
goto error;
}
l = get_mb_string(im, local_mb_buf, rhs_keysym);
while (b->mbused + l + 1 > b->mbsize) {
b->mbsize = b->mbsize ? b->mbsize * 1.5 : 1024;
if (! (b->mb = Xrealloc (b->mb, b->mbsize)) )
goto error;
}
rhs_string_mb = &b->mb[b->mbused];
b->mbused += l + 1;
memcpy(rhs_string_mb, local_mb_buf, l);
rhs_string_mb[l] = '\0';
} else {
goto error;
}
l = _Xmbstowcs(local_wc_buf, rhs_string_mb, LOCAL_WC_BUFSIZE - 1);
if (l == LOCAL_WC_BUFSIZE - 1) {
local_wc_buf[l] = (wchar_t)'\0';
}
while (b->wcused + l + 1 > b->wcsize) {
b->wcsize = b->wcsize ? b->wcsize * 1.5 : 512;
if (! (b->wc = Xrealloc (b->wc, sizeof(wchar_t) * b->wcsize)) )
goto error;
}
rhs_string_wc = &b->wc[b->wcused];
b->wcused += l + 1;
memcpy((char *)rhs_string_wc, (char *)local_wc_buf, (l + 1) * sizeof(wchar_t) );
l = _Xmbstoutf8(local_utf8_buf, rhs_string_mb, LOCAL_UTF8_BUFSIZE - 1);
if (l == LOCAL_UTF8_BUFSIZE - 1) {
local_utf8_buf[l] = '\0';
}
while (b->utf8used + l + 1 > b->utf8size) {
b->utf8size = b->utf8size ? b->utf8size * 1.5 : 1024;
if (! (b->utf8 = Xrealloc (b->utf8, b->utf8size)) )
goto error;
}
rhs_string_utf8 = &b->utf8[b->utf8used];
b->utf8used += l + 1;
memcpy(rhs_string_utf8, local_utf8_buf, l + 1);
for (i = 0; i < n; i++) {
for (t = *top; t; t = b->tree[t].next) {
if (buf[i].keysym == b->tree[t].keysym &&
buf[i].modifier == b->tree[t].modifier &&
buf[i].modifier_mask == b->tree[t].modifier_mask) {
break;
}
}
if (t) {
p = &b->tree[t];
top = &p->succession;
} else {
while (b->treeused >= b->treesize) {
DefTree *old = b->tree;
int oldsize = b->treesize;
b->treesize = b->treesize ? b->treesize * 1.5 : 256;
if (! (b->tree = Xrealloc (b->tree, sizeof(DefTree) * b->treesize)) )
goto error;
if (top >= (DTIndex *) old && top < (DTIndex *) &old[oldsize])
top = (DTIndex *) (((char *) top) + (((char *)b->tree)-(char *)old));
}
p = &b->tree[b->treeused];
p->keysym = buf[i].keysym;
p->modifier = buf[i].modifier;
p->modifier_mask = buf[i].modifier_mask;
p->succession = 0;
p->next = *top;
p->mb = 0;
p->wc = 0;
p->utf8 = 0;
p->ks = NoSymbol;
*top = b->treeused;
top = &p->succession;
b->treeused++;
}
}
/* old entries no longer freed... */
p->mb = rhs_string_mb - b->mb;
p->wc = rhs_string_wc - b->wc;
p->utf8 = rhs_string_utf8 - b->utf8;
p->ks = rhs_keysym;
return(n);
error:
while (token != ENDOFLINE && token != ENDOFFILE) {
token = nexttoken(fp, tokenbuf, &lastch);
}
return(0);
}
void
_XimParseStringFile(
FILE *fp,
Xim im)
{
char tb[8192];
char* tbp;
struct stat st;
if (fstat (fileno (fp), &st) != -1) {
unsigned long size = (unsigned long) st.st_size;
if (size <= sizeof tb) tbp = tb;
else tbp = malloc (size);
if (tbp != NULL) {
while (parseline(fp, im, tbp) >= 0) {}
if (tbp != tb) free (tbp);
}
}
}
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBGeom.c
|
<reponame>astrangeguy/libx11-debian-mirror
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#ifdef DEBUG
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#endif
#define NEED_MAP_READERS
#include "Xlibint.h"
#include <X11/extensions/XKBgeom.h>
#include <X11/extensions/XKBproto.h>
#include "XKBlibint.h"
#ifndef MINSHORT
#define MINSHORT -32768
#endif
#ifndef MAXSHORT
#define MAXSHORT 32767
#endif
/***====================================================================***/
static void
_XkbCheckBounds(XkbBoundsPtr bounds,int x,int y)
{
if (x<bounds->x1) bounds->x1= x;
if (x>bounds->x2) bounds->x2= x;
if (y<bounds->y1) bounds->y1= y;
if (y>bounds->y2) bounds->y2= y;
return;
}
Bool
XkbComputeShapeBounds(XkbShapePtr shape)
{
register int o,p;
XkbOutlinePtr outline;
XkbPointPtr pt;
if ((!shape)||(shape->num_outlines<1))
return False;
shape->bounds.x1= shape->bounds.y1= MAXSHORT;
shape->bounds.x2= shape->bounds.y2= MINSHORT;
for (outline=shape->outlines,o=0;o<shape->num_outlines;o++,outline++) {
for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
_XkbCheckBounds(&shape->bounds,pt->x,pt->y);
}
if (outline->num_points<2) {
_XkbCheckBounds(&shape->bounds,0,0);
}
}
return True;
}
Bool
XkbComputeShapeTop(XkbShapePtr shape,XkbBoundsPtr bounds)
{
register int p;
XkbOutlinePtr outline;
XkbPointPtr pt;
if ((!shape)||(shape->num_outlines<1))
return False;
if (shape->approx) outline= shape->approx;
else outline= &shape->outlines[shape->num_outlines-1];
if (outline->num_points<2) {
bounds->x1= bounds->y1= 0;
bounds->x2= bounds->y2= 0;
}
else {
bounds->x1= bounds->y1= MAXSHORT;
bounds->x2= bounds->y2= MINSHORT;
}
for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) {
_XkbCheckBounds(bounds,pt->x,pt->y);
}
return True;
}
Bool
XkbComputeRowBounds(XkbGeometryPtr geom,XkbSectionPtr section,XkbRowPtr row)
{
register int k,pos;
XkbKeyPtr key;
XkbBoundsPtr bounds,sbounds;
if ((!geom)||(!section)||(!row))
return False;
bounds= &row->bounds;
bzero(bounds,sizeof(XkbBoundsRec));
for (key=row->keys,pos=k=0;k<row->num_keys;k++,key++) {
sbounds= &XkbKeyShape(geom,key)->bounds;
_XkbCheckBounds(bounds,pos,0);
if (!row->vertical) {
if (key->gap!=0) {
pos+= key->gap;
_XkbCheckBounds(bounds,pos,0);
}
_XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
_XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
pos+= sbounds->x2;
}
else {
if (key->gap!=0) {
pos+= key->gap;
_XkbCheckBounds(bounds,0,pos);
}
_XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1);
_XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2);
pos+= sbounds->y2;
}
}
return True;
}
Bool
XkbComputeSectionBounds(XkbGeometryPtr geom,XkbSectionPtr section)
{
register int i;
XkbShapePtr shape;
XkbRowPtr row;
XkbDoodadPtr doodad;
XkbBoundsPtr bounds,rbounds;
if ((!geom)||(!section))
return False;
bounds= §ion->bounds;
bzero(bounds,sizeof(XkbBoundsRec));
for (i=0,row=section->rows;i<section->num_rows;i++,row++) {
if (!XkbComputeRowBounds(geom,section,row))
return False;
rbounds= &row->bounds;
_XkbCheckBounds(bounds,row->left+rbounds->x1,row->top+rbounds->y1);
_XkbCheckBounds(bounds,row->left+rbounds->x2,row->top+rbounds->y2);
}
for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) {
static XkbBoundsRec tbounds;
switch (doodad->any.type) {
case XkbOutlineDoodad:
case XkbSolidDoodad:
shape= XkbShapeDoodadShape(geom,&doodad->shape);
rbounds= &shape->bounds;
break;
case XkbTextDoodad:
tbounds.x1= doodad->text.left;
tbounds.y1= doodad->text.top;
tbounds.x2= tbounds.x1+doodad->text.width;
tbounds.y2= tbounds.y1+doodad->text.height;
rbounds= &tbounds;
break;
case XkbIndicatorDoodad:
shape= XkbIndicatorDoodadShape(geom,&doodad->indicator);
rbounds= &shape->bounds;
break;
case XkbLogoDoodad:
shape= XkbLogoDoodadShape(geom,&doodad->logo);
rbounds= &shape->bounds;
break;
default:
tbounds.x1= tbounds.x2= doodad->any.left;
tbounds.y1= tbounds.y2= doodad->any.top;
rbounds= &tbounds;
break;
}
_XkbCheckBounds(bounds,rbounds->x1,rbounds->y1);
_XkbCheckBounds(bounds,rbounds->x2,rbounds->y2);
}
return True;
}
/***====================================================================***/
char *
XkbFindOverlayForKey(XkbGeometryPtr geom,XkbSectionPtr wanted,char *under)
{
int s;
XkbSectionPtr section;
if ((geom==NULL)||(under==NULL)||(geom->num_sections<1))
return NULL;
if (wanted)
section= wanted;
else section= geom->sections;
for (s=0;s<geom->num_sections;s++,section++) {
XkbOverlayPtr ol;
int o;
if (section->num_overlays<1)
continue;
for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) {
XkbOverlayRowPtr row;
int r;
for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) {
XkbOverlayKeyPtr key;
int k;
for (k=0,key=row->keys;k<row->num_keys;k++,key++) {
if (strncmp(under,key->under.name,XkbKeyNameLength)==0)
return key->over.name;
}
}
}
if (wanted!=NULL)
break;
}
return NULL;
}
/***====================================================================***/
static Status
_XkbReadGeomProperties( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
xkbGetGeometryReply * rep)
{
Status rtrn;
if (rep->nProperties<1)
return Success;
if ((rtrn=XkbAllocGeomProps(geom,rep->nProperties))==Success) {
register int i;
register Bool ok;
char *name,*value;
ok= True;
for (i=0;(i<rep->nProperties)&&ok;i++) {
name=NULL;
value=NULL;
ok= _XkbGetReadBufferCountedString(buf,&name)&&ok;
ok= _XkbGetReadBufferCountedString(buf,&value)&&ok;
ok= ok&&(XkbAddGeomProperty(geom,name,value)!=NULL);
if (name)
_XkbFree(name);
if (value)
_XkbFree(value);
}
if (ok) rtrn= Success;
else rtrn= BadLength;
}
return rtrn;
}
static Status
_XkbReadGeomKeyAliases( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
xkbGetGeometryReply * rep)
{
Status rtrn;
if (rep->nKeyAliases<1)
return Success;
if ((rtrn=XkbAllocGeomKeyAliases(geom,rep->nKeyAliases))==Success) {
if (!_XkbCopyFromReadBuffer(buf,(char *)geom->key_aliases,
(rep->nKeyAliases*XkbKeyNameLength*2)))
return BadLength;
geom->num_key_aliases= rep->nKeyAliases;
return Success;
}
else { /* alloc failed, just skip the aliases */
_XkbSkipReadBufferData(buf,(rep->nKeyAliases*XkbKeyNameLength*2));
}
return rtrn;
}
static Status
_XkbReadGeomColors( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
xkbGetGeometryReply * rep)
{
Status rtrn;
if (rep->nColors<1)
return Success;
if ((rtrn=XkbAllocGeomColors(geom,rep->nColors))==Success) {
register int i;
char *spec;
for (i=0;i<rep->nColors;i++) {
spec = NULL;
if (!_XkbGetReadBufferCountedString(buf,&spec))
rtrn = BadLength;
else if (XkbAddGeomColor(geom,spec,geom->num_colors)==NULL)
rtrn = BadAlloc;
if (spec)
_XkbFree(spec);
if (rtrn != Success)
return rtrn;
}
return Success;
}
return rtrn;
}
static Status
_XkbReadGeomShapes( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
xkbGetGeometryReply * rep)
{
register int i;
Status rtrn;
if (rep->nShapes<1)
return Success;
if ((rtrn=XkbAllocGeomShapes(geom,rep->nShapes))!=Success)
return rtrn;
for (i=0;i<rep->nShapes;i++) {
xkbShapeWireDesc *shapeWire;
XkbShapePtr shape;
register int o;
shapeWire= (xkbShapeWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbShapeWireDesc));
if (!shapeWire)
return BadLength;
shape= XkbAddGeomShape(geom,shapeWire->name,shapeWire->nOutlines);
if (!shape)
return BadAlloc;
for (o=0;o<shapeWire->nOutlines;o++) {
xkbOutlineWireDesc *olWire;
XkbOutlinePtr ol;
register int p;
XkbPointPtr pt;
olWire= (xkbOutlineWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbOutlineWireDesc));
if (!olWire)
return BadLength;
ol= XkbAddGeomOutline(shape,olWire->nPoints);
if (!ol)
return BadAlloc;
ol->corner_radius= olWire->cornerRadius;
for (p=0,pt=ol->points;p<olWire->nPoints;p++,pt++) {
xkbPointWireDesc * ptWire;
ptWire= (xkbPointWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbPointWireDesc));
if (!ptWire)
return BadLength;
pt->x= ptWire->x;
pt->y= ptWire->y;
}
ol->num_points= olWire->nPoints;
}
if (shapeWire->primaryNdx!=XkbNoShape)
shape->primary= &shape->outlines[shapeWire->primaryNdx];
else shape->primary= NULL;
if (shapeWire->approxNdx!=XkbNoShape)
shape->approx= &shape->outlines[shapeWire->approxNdx];
else shape->approx= NULL;
XkbComputeShapeBounds(shape);
}
return Success;
}
static Status
_XkbReadGeomDoodad( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
XkbSectionPtr section)
{
XkbDoodadPtr doodad;
xkbDoodadWireDesc * doodadWire;
doodadWire= (xkbDoodadWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbDoodadWireDesc));
if (!doodadWire)
return BadLength;
doodad= XkbAddGeomDoodad(geom,section,doodadWire->any.name);
if (!doodad)
return BadAlloc;
doodad->any.type= doodadWire->any.type;
doodad->any.priority= doodadWire->any.priority;
doodad->any.top= doodadWire->any.top;
doodad->any.left= doodadWire->any.left;
doodad->any.angle= doodadWire->any.angle;
switch (doodad->any.type) {
case XkbOutlineDoodad:
case XkbSolidDoodad:
doodad->shape.color_ndx= doodadWire->shape.colorNdx;
doodad->shape.shape_ndx= doodadWire->shape.shapeNdx;
break;
case XkbTextDoodad:
doodad->text.width= doodadWire->text.width;
doodad->text.height= doodadWire->text.height;
doodad->text.color_ndx= doodadWire->text.colorNdx;
if (!_XkbGetReadBufferCountedString(buf,&doodad->text.text))
return BadLength;
if (!_XkbGetReadBufferCountedString(buf,&doodad->text.font))
return BadLength;
break;
case XkbIndicatorDoodad:
doodad->indicator.shape_ndx= doodadWire->indicator.shapeNdx;
doodad->indicator.on_color_ndx= doodadWire->indicator.onColorNdx;
doodad->indicator.off_color_ndx= doodadWire->indicator.offColorNdx;
break;
case XkbLogoDoodad:
doodad->logo.color_ndx= doodadWire->logo.colorNdx;
doodad->logo.shape_ndx= doodadWire->logo.shapeNdx;
if (!_XkbGetReadBufferCountedString(buf,&doodad->logo.logo_name))
return BadLength;
break;
default:
return BadValue;
}
return Success;
}
static Status
_XkbReadGeomOverlay( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
XkbSectionPtr section)
{
XkbOverlayPtr ol;
xkbOverlayWireDesc * olWire;
register int r;
olWire= (xkbOverlayWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayWireDesc));
if (olWire==NULL)
return BadLength;
ol= XkbAddGeomOverlay(section,olWire->name,olWire->nRows);
if (ol==NULL)
return BadLength;
for (r=0;r<olWire->nRows;r++) {
register int k;
XkbOverlayRowPtr row;
xkbOverlayRowWireDesc * rowWire;
xkbOverlayKeyWireDesc * keyWire;
rowWire= (xkbOverlayRowWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayRowWireDesc));
if (rowWire==NULL)
return BadLength;
row= XkbAddGeomOverlayRow(ol,rowWire->rowUnder,rowWire->nKeys);
row->row_under= rowWire->rowUnder;
if (!row)
return BadAlloc;
if (rowWire->nKeys<1)
continue;
keyWire= (xkbOverlayKeyWireDesc *)
_XkbGetReadBufferPtr(buf,
SIZEOF(xkbOverlayKeyWireDesc)*rowWire->nKeys);
if (keyWire==NULL)
return BadLength;
for (k=0;k<rowWire->nKeys;k++,keyWire++,row->num_keys++) {
memcpy(row->keys[row->num_keys].over.name,keyWire->over,
XkbKeyNameLength);
memcpy(row->keys[row->num_keys].under.name,keyWire->under,
XkbKeyNameLength);
}
}
return Success;
}
static Status
_XkbReadGeomSections( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
xkbGetGeometryReply * rep)
{
register int s;
XkbSectionPtr section;
xkbSectionWireDesc * sectionWire;
Status rtrn;
if (rep->nSections<1)
return Success;
if ((rtrn=XkbAllocGeomSections(geom,rep->nSections))!=Success)
return rtrn;
for (s=0;s<rep->nSections;s++) {
sectionWire= (xkbSectionWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbSectionWireDesc));
if (!sectionWire)
return BadLength;
section= XkbAddGeomSection(geom,sectionWire->name,sectionWire->nRows,
sectionWire->nDoodads,
sectionWire->nOverlays);
if (!section)
return BadAlloc;
section->top= sectionWire->top;
section->left= sectionWire->left;
section->width= sectionWire->width;
section->height= sectionWire->height;
section->angle= sectionWire->angle;
section->priority= sectionWire->priority;
if (sectionWire->nRows>0) {
register int r;
XkbRowPtr row;
xkbRowWireDesc * rowWire;
for (r=0;r<sectionWire->nRows;r++) {
rowWire= (xkbRowWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbRowWireDesc));
if (!rowWire)
return BadLength;
row= XkbAddGeomRow(section,rowWire->nKeys);
if (!row)
return BadAlloc;
row->top= rowWire->top;
row->left= rowWire->left;
row->vertical= rowWire->vertical;
if (rowWire->nKeys>0) {
register int k;
XkbKeyPtr key;
xkbKeyWireDesc * keyWire;
for (k=0;k<rowWire->nKeys;k++) {
keyWire= (xkbKeyWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbKeyWireDesc));
if (!keyWire)
return BadLength;
key= XkbAddGeomKey(row);
if (!key)
return BadAlloc;
memcpy(key->name.name,keyWire->name,XkbKeyNameLength);
key->gap= keyWire->gap;
key->shape_ndx= keyWire->shapeNdx;
key->color_ndx= keyWire->colorNdx;
}
}
}
}
if (sectionWire->nDoodads>0) {
register int d;
for (d=0;d<sectionWire->nDoodads;d++) {
if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success)
return rtrn;
}
}
if (sectionWire->nOverlays>0) {
register int o;
for (o=0;o<sectionWire->nOverlays;o++) {
if ((rtrn=_XkbReadGeomOverlay(buf,geom,section))!=Success)
return rtrn;
}
}
}
return Success;
}
static Status
_XkbReadGeomDoodads( XkbReadBufferPtr buf,
XkbGeometryPtr geom,
xkbGetGeometryReply * rep)
{
register int d;
Status rtrn;
if (rep->nDoodads<1)
return Success;
if ((rtrn=XkbAllocGeomDoodads(geom,rep->nDoodads))!=Success)
return rtrn;
for (d=0;d<rep->nDoodads;d++) {
if ((rtrn=_XkbReadGeomDoodad(buf,geom,NULL))!=Success)
return rtrn;
}
return Success;
}
Status
_XkbReadGetGeometryReply( Display * dpy,
xkbGetGeometryReply * rep,
XkbDescPtr xkb,
int * nread_rtrn)
{
XkbGeometryPtr geom;
geom= _XkbTypedCalloc(1,XkbGeometryRec);
if (!geom)
return BadAlloc;
if (xkb->geom)
XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
xkb->geom= geom;
geom->name= rep->name;
geom->width_mm= rep->widthMM;
geom->height_mm= rep->heightMM;
if (rep->length) {
XkbReadBufferRec buf;
int left;
if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) {
Status status= Success;
if (nread_rtrn)
*nread_rtrn= (int)rep->length*4;
if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font))
status= BadLength;
if (status==Success)
status= _XkbReadGeomProperties(&buf,geom,rep);
if (status==Success)
status= _XkbReadGeomColors(&buf,geom,rep);
if (status==Success)
status= _XkbReadGeomShapes(&buf,geom,rep);
if (status==Success)
status= _XkbReadGeomSections(&buf,geom,rep);
if (status==Success)
status= _XkbReadGeomDoodads(&buf,geom,rep);
if (status==Success)
status= _XkbReadGeomKeyAliases(&buf,geom,rep);
left= _XkbFreeReadBuffer(&buf);
if ((status!=Success) || left || buf.error) {
if (status==Success)
status= BadLength;
XkbFreeGeometry(geom,XkbGeomAllMask,True);
xkb->geom= NULL;
return status;
}
geom->base_color= &geom->colors[rep->baseColorNdx];
geom->label_color= &geom->colors[rep->labelColorNdx];
}
else {
XkbFreeGeometry(geom,XkbGeomAllMask,True);
xkb->geom= NULL;
return BadAlloc;
}
}
return Success;
}
Status
XkbGetGeometry(Display *dpy,XkbDescPtr xkb)
{
xkbGetGeometryReq *req;
xkbGetGeometryReply rep;
Status status;
if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
return BadAccess;
LockDisplay(dpy);
GetReq(kbGetGeometry, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetGeometry;
req->deviceSpec = xkb->device_spec;
req->name= None;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
status = BadImplementation;
else if (!rep.found)
status = BadName;
else
status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
Status
XkbGetNamedGeometry(Display *dpy,XkbDescPtr xkb,Atom name)
{
xkbGetGeometryReq *req;
xkbGetGeometryReply rep;
Status status;
if ( (name==None) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
return BadAccess;
LockDisplay(dpy);
GetReq(kbGetGeometry, req);
req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetGeometry;
req->deviceSpec = xkb->device_spec;
req->name= (CARD32)name;
if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.found))
status = BadImplementation;
else if (!rep.found)
status = BadName;
else
status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL);
UnlockDisplay(dpy);
SyncHandle();
return status;
}
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBlibint.h
|
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#ifndef _XKBLIBINT_H_
#define _XKBLIBINT_H_
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#define XkbMapPending (1<<0)
#define XkbXlibNewKeyboard (1<<1)
typedef int (*XkbKSToMBFunc)(
XPointer /* priv */,
KeySym /* sym */,
char * /* buf */,
int /* len */,
int * /* extra_rtrn */
);
typedef KeySym (*XkbMBToKSFunc)(
XPointer /* priv */,
char * /* buf */,
int /* len */,
Status * /* status */
);
typedef KeySym (*XkbToUpperFunc)(
KeySym /* sym */
);
typedef struct _XkbConverters {
XkbKSToMBFunc KSToMB;
XPointer KSToMBPriv;
XkbMBToKSFunc MBToKS;
XPointer MBToKSPriv;
XkbToUpperFunc KSToUpper;
} XkbConverters;
extern XkbInternAtomFunc _XkbInternAtomFunc;
extern XkbGetAtomNameFunc _XkbGetAtomNameFunc;
typedef struct _XkbInfoRec {
unsigned flags;
unsigned xlib_ctrls;
XExtCodes *codes;
int srv_major;
int srv_minor;
unsigned selected_events;
unsigned short selected_nkn_details;
unsigned short selected_map_details;
XkbDescRec *desc;
XkbMapChangesRec changes;
Atom composeLED;
XkbConverters cvt;
XkbConverters latin1cvt;
} XkbInfoRec, *XkbInfoPtr;
#define _XkbUnavailable(d) \
(((d)->flags&XlibDisplayNoXkb) ||\
((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d)))
#define _XkbCheckPendingRefresh(d,xi) {\
if ((xi)->flags&XkbXlibNewKeyboard)\
_XkbReloadDpy((d));\
else if ((xi)->flags&XkbMapPending) {\
if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) {\
LockDisplay((d));\
(xi)->changes.changed= 0;\
UnlockDisplay((d));\
}\
}\
}
#define _XkbNeedModmap(i) ((!(i)->desc->map)||(!(i)->desc->map->modmap))
/*
* mask of the events that the "invisible" XKB support in Xlib needs
*/
#define XKB_XLIB_MAP_MASK (XkbAllClientInfoMask)
/*
* Handy helper macros
*/
#define XKB_INSURE_SIZE(f,t,nNum,oNum) {\
if ((f)==NULL) \
(f)=(t *)Xmalloc(sizeof(t)*(nNum));\
else if ((nNum)<(oNum))\
(f)=(t *)Xrealloc((f),sizeof(t)*(nNum));\
}
typedef struct _XkbReadBuffer {
int error;
int size;
char *start;
char *data;
} XkbReadBufferRec,*XkbReadBufferPtr;
#define _XkbAlloc(s) Xmalloc((s))
#define _XkbCalloc(n,s) Xcalloc((n),(s))
#define _XkbRealloc(o,s) Xrealloc((o),(s))
#define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t)))
#define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t)))
#define _XkbTypedRealloc(o,n,t) \
((o)?(t *)Xrealloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t))
#define _XkbClearElems(a,f,l,t) bzero(&(a)[f],((l)-(f)+1)*sizeof(t))
#define _XkbFree(p) Xfree(p)
_XFUNCPROTOBEGIN
extern void _XkbReloadDpy(
Display * /* dpy */
);
extern KeySym _XKeycodeToKeysym(
Display* /* display */,
#if NeedWidePrototypes
unsigned int /* keycode */,
#else
KeyCode /* keycode */,
#endif
int /* index */
);
extern KeyCode _XKeysymToKeycode(
Display* /* display */,
KeySym /* keysym */
);
extern KeySym _XLookupKeysym(
XKeyEvent* /* key_event */,
int /* index */
);
extern int _XRefreshKeyboardMapping(
XMappingEvent* /* event_map */
);
extern unsigned _XKeysymToModifiers(
Display * /* dpy */,
KeySym /* ks */
);
extern int _XTranslateKey(
register Display * /* dpy */,
KeyCode /* keycode */,
register unsigned int /* modifiers */,
unsigned int * /* modifiers_return */,
KeySym * /* keysym_return */
);
extern int _XTranslateKeySym(
Display * /* dpy */,
register KeySym /* symbol */,
unsigned int /* modifiers */,
char * /* buffer */,
int /* nbytes */
);
extern int _XLookupString(
register XKeyEvent * /* event */,
char * /* buffer */,
int /* nbytes */,
KeySym * /* keysym */,
XComposeStatus * /* status */
);
extern void _XkbNoteCoreMapChanges(
XkbMapChangesRec * /* old */,
XMappingEvent * /* new */,
unsigned int /* wanted */
);
extern int _XkbInitReadBuffer(
Display * /* dpy */,
XkbReadBufferPtr /* buf */,
int /* size */
);
extern int _XkbSkipReadBufferData(
XkbReadBufferPtr /* from */,
int /* size */
);
extern int _XkbCopyFromReadBuffer(
XkbReadBufferPtr /* from */,
char * /* to */,
int /* size */
);
#if defined(WORD64) || defined(LONG64)
extern int _XkbReadCopyData32(
int * /* from */,
long * /* to */,
int /* num_words */
);
extern int _XkbWriteCopyData32(
unsigned long * /* from */,
CARD32 * /* to */,
int /* num_words */
);
extern int _XkbReadBufferCopy32(
XkbReadBufferPtr /* from */,
long * /* to */,
int /* size */
);
#else
#define _XkbReadCopyData32(f,t,s) memcpy((char *)(t),(char *)(f),(s)*4)
#define _XkbWriteCopyData32(f,t,s) memcpy((char *)(t),(char *)(f),(s)*4)
#define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f,(char *)t,(s)*4)
#endif
#ifndef NO_DEC_BINARY_COMPATIBILITY
#define XKB_FORCE_INT_KEYSYM 1
#endif
#ifdef XKB_FORCE_INT_KEYSYM
extern int _XkbReadCopyKeySyms(
int * /* from */,
KeySym * /* to */,
int /* num_words */
);
extern int _XkbWriteCopyKeySyms(
KeySym * /* from */,
CARD32 * /* to */,
int /* num_words */
);
extern int _XkbReadBufferCopyKeySyms(
XkbReadBufferPtr /* from */,
#ifndef NO_DEC_BUG_FIX
KeySym * /* to */,
#else
long * /* to */,
#endif
int /* size */
);
#else
#define _XkbReadCopyKeySyms(f,t,n) _XkbReadCopyData32(f,t,n)
#define _XkbWriteCopyKeySyms(f,t,n) _XkbWriteCopyData32(f,t,n)
#define _XkbReadBufferCopyKeySyms(f,t,s) _XkbReadBufferCopy32(f,t,s)
#endif
extern char *_XkbPeekAtReadBuffer(
XkbReadBufferPtr /* from */,
int /* size */
);
extern char *_XkbGetReadBufferPtr(
XkbReadBufferPtr /* from */,
int /* size */
);
#define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t)))
extern int _XkbFreeReadBuffer(
XkbReadBufferPtr /* buf */
);
extern Bool
_XkbGetReadBufferCountedString(
XkbReadBufferPtr /* buf */,
char ** /* rtrn */
);
extern char *_XkbGetCharset(
void
);
extern int _XkbGetConverters(
const char * /* encoding_name */,
XkbConverters * /* cvt_rtrn */
);
#ifdef NEED_MAP_READERS
extern Status _XkbReadGetMapReply(
Display * /* dpy */,
xkbGetMapReply * /* rep */,
XkbDescRec * /* xkb */,
int * /* nread_rtrn */
);
extern Status _XkbReadGetCompatMapReply(
Display * /* dpy */,
xkbGetCompatMapReply * /* rep */,
XkbDescPtr /* xkb */,
int * /* nread_rtrn */
);
extern Status _XkbReadGetIndicatorMapReply(
Display * /* dpy */,
xkbGetIndicatorMapReply * /* rep */,
XkbDescPtr /* xkb */,
int * /* nread_rtrn */
);
extern Status _XkbReadGetNamesReply(
Display * /* dpy */,
xkbGetNamesReply * /* rep */,
XkbDescPtr /* xkb */,
int * /* nread_rtrn */
);
extern Status _XkbReadGetGeometryReply(
Display * /* dpy */,
xkbGetGeometryReply * /* rep */,
XkbDescPtr /* xkb */,
int * /* nread_rtrn */
);
#endif
_XFUNCPROTOEND
#endif /* _XKBLIBINT_H_ */
|
astrangeguy/libx11-debian-mirror
|
src/xlibi18n/lcUniConv/koi8_c.h
|
/*
* KOI8-C
*/
static const unsigned short koi8_c_2uni[128] = {
/* 0x80 */
0x0493, 0x0497, 0x049b, 0x049d, 0x04a3, 0x04af, 0x04b1, 0x04b3,
0x04b7, 0x04b9, 0x04bb, 0x2580, 0x04d9, 0x04e3, 0x04e9, 0x04ef,
/* 0x90 */
0x0492, 0x0496, 0x049a, 0x049c, 0x04a2, 0x04ae, 0x04b0, 0x04b2,
0x04b6, 0x04b8, 0x04ba, 0x2321, 0x04d8, 0x04e2, 0x04e8, 0x04ee,
/* 0xa0 */
0x00a0, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457,
0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0491, 0x045e, 0x045f,
/* 0xb0 */
0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407,
0x0486, 0x0409, 0x040a, 0x040b, 0x040c, 0x0490, 0x040e, 0x040f,
/* 0xc0 */
0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e,
/* 0xd0 */
0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a,
/* 0xe0 */
0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e,
/* 0xf0 */
0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a,
};
static int
koi8_c_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
{
unsigned char c = *s;
if (c < 0x80)
*pwc = (ucs4_t) c;
else
*pwc = (ucs4_t) koi8_c_2uni[c-0x80];
return 1;
}
static const unsigned char koi8_c_page00[1] = {
0xa0, /* 0xa0-0xa7 */
};
static const unsigned char koi8_c_page04[240] = {
0x00, 0xb3, 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, /* 0x00-0x07 */
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0x00, 0xbe, 0xbf, /* 0x08-0x0f */
0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, /* 0x10-0x17 */
0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, /* 0x18-0x1f */
0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, /* 0x20-0x27 */
0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, /* 0x28-0x2f */
0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, /* 0x30-0x37 */
0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, /* 0x38-0x3f */
0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, /* 0x40-0x47 */
0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, /* 0x48-0x4f */
0x00, 0xa3, 0xa1, 0xa2, 0xa4, 0xa5, 0xa6, 0xa7, /* 0x50-0x57 */
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0x00, 0xae, 0xaf, /* 0x58-0x5f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
0xbd, 0xad, 0x90, 0x80, 0x00, 0x00, 0x91, 0x81, /* 0x90-0x97 */
0x00, 0x00, 0x92, 0x82, 0x93, 0x83, 0x00, 0x00, /* 0x98-0x9f */
0x00, 0x00, 0x94, 0x84, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x85, /* 0xa8-0xaf */
0x96, 0x86, 0x97, 0x87, 0x00, 0x00, 0x98, 0x88, /* 0xb0-0xb7 */
0x99, 0x89, 0x9a, 0x8a, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
0x9c, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
0x00, 0x00, 0x9d, 0x8d, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
0x9e, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x9f, 0x8f, /* 0xe8-0xef */
};
static const unsigned char koi8_c_page22[1] = {
0xb0, /* 0x16-0x16 */
};
static int
koi8_c_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
{
unsigned char c = 0;
if (wc < 0x0080) {
*r = wc;
return 1;
}
else if (wc >= 0x00a0 && wc < 0x00a1)
c = koi8_c_page00[wc-0x00a0];
else if (wc >= 0x0400 && wc < 0x04ef)
c = koi8_c_page04[wc-0x0400];
else if (wc >= 0x2216 && wc < 0x2217)
c = koi8_c_page22[wc-0x2216];
if (c != 0) {
*r = c;
return 1;
}
return RET_ILSEQ;
}
|
astrangeguy/libx11-debian-mirror
|
src/locking.h
|
<filename>src/locking.h
/*
Copyright 1992, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
/*
* Author: <NAME>, MIT X Consortium
*
* locking.h - data types for C Threads locking.
* Used by XlibInt.c, locking.c, LockDis.c
*/
#ifndef _X_locking_H_
#define _X_locking_H_
#define xmalloc(s) Xmalloc(s)
#define xfree(s) Xfree(s)
#include <X11/Xthreads.h>
struct _XCVList {
xcondition_t cv;
xReply *buf;
struct _XCVList *next;
};
extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */
void
);
/* Display->lock is a pointer to one of these */
struct _XLockInfo {
xmutex_t mutex; /* mutex for critical sections */
int reply_bytes_left; /* nbytes of the reply still to read */
Bool reply_was_read; /* _XReadEvents read a reply for _XReply */
struct _XCVList *reply_awaiters; /* list of CVs for _XReply */
struct _XCVList **reply_awaiters_tail;
struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */
struct _XCVList **event_awaiters_tail;
Bool reply_first; /* who may read, reply queue or event queue */
/* for XLockDisplay */
int locking_level; /* how many times into XLockDisplay we are */
xthread_t locking_thread; /* thread that did XLockDisplay */
xcondition_t cv; /* wait if another thread has XLockDisplay */
xthread_t reading_thread; /* cache */
xthread_t conni_thread; /* thread in XProcessInternalConnection */
xcondition_t writers; /* wait for writable */
int num_free_cvls;
struct _XCVList *free_cvls;
/* used only in XlibInt.c */
void (*pop_reader)(
Display* /* dpy */,
struct _XCVList** /* list */,
struct _XCVList*** /* tail */
);
struct _XCVList *(*push_reader)(
Display * /* dpy */,
struct _XCVList*** /* tail */
);
void (*condition_wait)(
xcondition_t /* cv */,
xmutex_t /* mutex */
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
, char* /* file */,
int /* line */
#endif
);
void (*internal_lock_display)(
Display* /* dpy */,
Bool /* wskip */
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
, char* /* file */,
int /* line */
#endif
);
/* used in XlibInt.c and locking.c */
void (*condition_signal)(
xcondition_t /* cv */
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
, char* /* file */,
int /* line */
#endif
);
void (*condition_broadcast)(
xcondition_t /* cv */
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
, char* /* file */,
int /* line */
#endif
);
/* used in XlibInt.c and XLockDis.c */
void (*lock_wait)(
Display* /* dpy */
);
void (*user_lock_display)(
Display* /* dpy */
);
void (*user_unlock_display)(
Display* /* dpy */
);
struct _XCVList *(*create_cvl)(
Display * /* dpy */
);
};
#define UnlockNextEventReader(d) if ((d)->lock) \
(*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail)
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
#define ConditionWait(d,c) if ((d)->lock) \
(*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__)
#define ConditionSignal(d,c) if ((d)->lock) \
(*(d)->lock->condition_signal)(c,__FILE__,__LINE__)
#define ConditionBroadcast(d,c) if ((d)->lock) \
(*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__)
#else
#define ConditionWait(d,c) if ((d)->lock) \
(*(d)->lock->condition_wait)(c, (d)->lock->mutex)
#define ConditionSignal(d,c) if ((d)->lock) \
(*(d)->lock->condition_signal)(c)
#define ConditionBroadcast(d,c) if ((d)->lock) \
(*(d)->lock->condition_broadcast)(c)
#endif
typedef struct _LockInfoRec {
xmutex_t lock;
} LockInfoRec;
/* XOpenDis.c */
extern int (*_XInitDisplayLock_fn)(Display *dpy);
extern void (*_XFreeDisplayLock_fn)(Display *dpy);
#endif /* _X_locking_H_ */
|
astrangeguy/libx11-debian-mirror
|
src/ErrHndlr.c
|
/*
Copyright 1986, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
/*
* XErrorHandler - This procedure sets the X non-fatal error handler
* (_XErrorFunction) to be the specified routine. If NULL is passed in
* the original error handler is restored.
*/
XErrorHandler
XSetErrorHandler(XErrorHandler handler)
{
int (*oldhandler)(Display *dpy, XErrorEvent *event);
_XLockMutex(_Xglobal_lock);
oldhandler = _XErrorFunction;
if (!oldhandler)
oldhandler = _XDefaultError;
if (handler != NULL) {
_XErrorFunction = handler;
}
else {
_XErrorFunction = _XDefaultError;
}
_XUnlockMutex(_Xglobal_lock);
return (XErrorHandler) oldhandler;
}
/*
* XIOErrorHandler - This procedure sets the X fatal I/O error handler
* (_XIOErrorFunction) to be the specified routine. If NULL is passed in
* the original error handler is restored.
*/
XIOErrorHandler
XSetIOErrorHandler(XIOErrorHandler handler)
{
int (*oldhandler)(Display *dpy);
_XLockMutex(_Xglobal_lock);
oldhandler = _XIOErrorFunction;
if (!oldhandler)
oldhandler = _XDefaultIOError;
if (handler != NULL) {
_XIOErrorFunction = handler;
}
else {
_XIOErrorFunction = _XDefaultIOError;
}
_XUnlockMutex(_Xglobal_lock);
return (XIOErrorHandler) oldhandler;
}
|
astrangeguy/libx11-debian-mirror
|
src/xcms/cmsInt.c
|
/*
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
* All Rights Reserved
*
* This file is a component of an X Window System-specific implementation
* of Xcms based on the TekColor Color Management System. Permission is
* hereby granted to use, copy, modify, sell, and otherwise distribute this
* software and its documentation for any purpose and without fee, provided
* that this copyright, permission, and disclaimer notice is reproduced in
* all copies of this software and in supporting documentation. TekColor
* is a trademark of Tektronix, Inc.
*
* Tektronix makes no representation about the suitability of this software
* for any purpose. It is provided "as is" and with all faults.
*
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
*
*
* NAME
* XcmsInt.c - Xcms API utility routines
*
* DESCRIPTION
* Xcms Application Program Interface (API) utility
* routines for hanging information directly onto
* the Display structure.
*
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include "Xcmsint.h"
#include "Cv.h"
#ifndef XCMSCOMPPROC
# define XCMSCOMPPROC XcmsTekHVCClipC
#endif
/* forward/static */
static void _XcmsFreeDefaultCCCs(Display *dpy);
/************************************************************************
* *
* API PRIVATE ROUTINES *
* *
************************************************************************/
/*
* NAME
* _XcmsCopyPointerArray
*
* SYNOPSIS
*/
XPointer *
_XcmsCopyPointerArray(
XPointer *pap)
/*
* DESCRIPTION
* Copies an array of NULL terminated pointers.
*
* RETURNS
* Returns NULL if failed; otherwise the address to
* the copy.
*
*/
{
XPointer *newArray;
char **tmp;
int n;
for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
n++; /* add 1 to include the NULL pointer */
if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) {
memcpy((char *)newArray, (char *)pap,
(unsigned)(n * sizeof(XPointer)));
}
return((XPointer *)newArray);
}
/*
* NAME
* _XcmsFreePointerArray
*
* SYNOPSIS
*/
void
_XcmsFreePointerArray(
XPointer *pap)
/*
* DESCRIPTION
* Frees an array of NULL terminated pointers.
*
* RETURNS
* void
*
*/
{
Xfree(pap);
}
/*
* NAME
* _XcmsPushPointerArray
*
* SYNOPSIS
*/
XPointer *
_XcmsPushPointerArray(
XPointer *pap,
XPointer p,
XPointer *papNoFree)
/*
* DESCRIPTION
* Places the specified pointer at the head of an array of NULL
* terminated pointers.
*
* RETURNS
* Returns NULL if failed; otherwise the address to
* the head of the array.
*
*/
{
XPointer *newArray;
char **tmp;
int n;
for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
/* add 2: 1 for the new pointer and another for the NULL pointer */
n += 2;
if ((newArray = (XPointer *)Xmalloc(n * sizeof(XPointer)))) {
memcpy((char *)(newArray+1),(char *)pap,
(unsigned)((n-1) * sizeof(XPointer)));
*newArray = p;
}
if (pap != papNoFree) {
_XcmsFreePointerArray(pap);
}
return((XPointer *)newArray);
}
/*
* NAME
* _XcmsInitDefaultCCCs
*
* SYNOPSIS
*/
int
_XcmsInitDefaultCCCs(
Display *dpy)
/*
* DESCRIPTION
* Initializes the Xcms per Display Info structure
* (XcmsPerDpyInfo).
*
* RETURNS
* Returns 0 if failed; otherwise non-zero.
*
*/
{
int nScrn = ScreenCount(dpy);
int i;
XcmsCCC ccc;
if (nScrn <= 0) {
return(0);
}
/*
* Create an array of XcmsCCC structures, one for each screen.
* They serve as the screen's default CCC.
*/
if (!(ccc = (XcmsCCC)
Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) {
return(0);
}
dpy->cms.defaultCCCs = (XPointer)ccc;
dpy->free_funcs->defaultCCCs = _XcmsFreeDefaultCCCs;
for (i = 0; i < nScrn; i++, ccc++) {
ccc->dpy = dpy;
ccc->screenNumber = i;
ccc->visual = DefaultVisual(dpy, i);
/*
* Used calloc to allocate memory so:
* ccc->clientWhitePt->format == XcmsUndefinedFormat
* ccc->gamutCompProc == NULL
* ccc->whitePtAdjProc == NULL
* ccc->pPerScrnInfo = NULL
*
* Don't need to create XcmsPerScrnInfo and its functionSet and
* pScreenData components until the default CCC is accessed.
* Note that the XcmsDefaultCCC routine calls _XcmsInitScrnInto
* to do this.
*/
ccc->gamutCompProc = XCMSCOMPPROC;
}
return(1);
}
/*
* NAME
* _XcmsFreeDefaultCCCs - Free Default CCCs and its PerScrnInfo
*
* SYNOPSIS
*/
static void
_XcmsFreeDefaultCCCs(
Display *dpy)
/*
* DESCRIPTION
* This routine frees the default XcmsCCC's associated with
* each screen and its associated substructures as neccessary.
*
* RETURNS
* void
*
*
*/
{
int nScrn = ScreenCount(dpy);
XcmsCCC ccc;
int i;
/*
* Free Screen data in each DefaultCCC
* Do not use XcmsFreeCCC here because it will not free
* DefaultCCC's.
*/
ccc = (XcmsCCC)dpy->cms.defaultCCCs;
for (i = nScrn; i--; ccc++) {
/*
* Check if XcmsPerScrnInfo exists.
*
* This is the only place where XcmsPerScrnInfo structures
* are freed since there is only one allocated per Screen.
* It just so happens that we place its reference in the
* default CCC.
*/
if (ccc->pPerScrnInfo) {
/* Check if SCCData exists */
if (ccc->pPerScrnInfo->state != XcmsInitNone
&& ccc->pPerScrnInfo->screenData) {
(*((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->screenFreeProc)
(ccc->pPerScrnInfo->screenData);
}
Xfree(ccc->pPerScrnInfo);
}
}
/*
* Free the array of XcmsCCC structures
*/
Xfree(dpy->cms.defaultCCCs);
dpy->cms.defaultCCCs = (XPointer)NULL;
}
/*
* NAME
* _XcmsInitScrnInfo
*
* SYNOPSIS
*/
int
_XcmsInitScrnInfo(
register Display *dpy,
int screenNumber)
/*
* DESCRIPTION
* Given a display and screen number, this routine attempts
* to initialize the Xcms per Screen Info structure
* (XcmsPerScrnInfo).
*
* RETURNS
* Returns zero if initialization failed; non-zero otherwise.
*/
{
XcmsFunctionSet **papSCCFuncSet = _XcmsSCCFuncSets;
XcmsCCC defaultccc;
/*
* Check if the XcmsCCC's for each screen has been created.
* Really dont need to be created until some routine uses the Xcms
* API routines.
*/
if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
if (!_XcmsInitDefaultCCCs(dpy)) {
return(0);
}
}
defaultccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber;
/*
* For each SCCFuncSet, try its pInitScrnFunc.
* If the function succeeds, then we got it!
*/
if (!defaultccc->pPerScrnInfo) {
/*
* This is one of two places where XcmsPerScrnInfo structures
* are allocated. There is one allocated per Screen that is
* shared among visuals that do not have specific intensity
* tables. Other XcmsPerScrnInfo structures are created
* for the latter (see XcmsCreateCCC). The ones created
* here are referenced by the default CCC.
*/
if (!(defaultccc->pPerScrnInfo = (XcmsPerScrnInfo *)
Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
return(0);
}
defaultccc->pPerScrnInfo->state = XcmsInitNone;
}
while (*papSCCFuncSet != NULL) {
if ((*(*papSCCFuncSet)->screenInitProc)(dpy, screenNumber,
defaultccc->pPerScrnInfo)) {
defaultccc->pPerScrnInfo->state = XcmsInitSuccess;
return(1);
}
papSCCFuncSet++;
}
/*
* Use Default SCCData
*/
return(_XcmsLRGB_InitScrnDefault(dpy, screenNumber, defaultccc->pPerScrnInfo));
}
/*
* NAME
* _XcmsFreeIntensityMaps
*
* SYNOPSIS
*/
void
_XcmsFreeIntensityMaps(
Display *dpy)
/*
* DESCRIPTION
* Frees all XcmsIntensityMap structures in the linked list
* and sets dpy->cms.perVisualIntensityMaps to NULL.
*
* RETURNS
* void
*
*/
{
XcmsIntensityMap *pNext, *pFree;
pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
while (pNext != NULL) {
pFree = pNext;
pNext = pNext->pNext;
(*pFree->pFreeScreenData)(pFree->screenData);
/* Now free the XcmsIntensityMap structure */
Xfree(pFree);
}
dpy->cms.perVisualIntensityMaps = (XPointer)NULL;
}
/*
* NAME
* _XcmsGetIntensityMap
*
* SYNOPSIS
*/
XcmsIntensityMap *
_XcmsGetIntensityMap(
Display *dpy,
Visual *visual)
/*
* DESCRIPTION
* Attempts to return a per-Visual intensity map.
*
* RETURNS
* Pointer to the XcmsIntensityMap structure if found;
* otherwise NULL
*
*/
{
VisualID targetID = visual->visualid;
XcmsIntensityMap *pNext;
pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
while (pNext != NULL) {
if (targetID == pNext->visualID) {
return(pNext);
}
pNext = pNext->pNext;
}
return((XcmsIntensityMap *)NULL);
}
|
astrangeguy/libx11-debian-mirror
|
src/GetNrmHint.c
|
<filename>src/GetNrmHint.c
/***********************************************************
Copyright 1988 by Wyse Technology, Inc., San Jose, Ca,
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL AND WYSE DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL DIGITAL OR WYSE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/*
Copyright 1987, 1988, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/Xlibint.h>
#include <X11/Xatom.h>
#include "Xatomtype.h"
#include <X11/Xutil.h>
#include <stdio.h>
Status XGetWMSizeHints (
Display *dpy,
Window w,
XSizeHints *hints,
long *supplied,
Atom property)
{
xPropSizeHints *prop = NULL;
Atom actual_type;
int actual_format;
unsigned long leftover;
unsigned long nitems;
if (XGetWindowProperty (dpy, w, property, 0L,
(long)NumPropSizeElements,
False, XA_WM_SIZE_HINTS, &actual_type,
&actual_format, &nitems, &leftover,
(unsigned char **)&prop)
!= Success)
return False;
if ((actual_type != XA_WM_SIZE_HINTS) ||
(nitems < OldNumPropSizeElements) || (actual_format != 32)) {
if (prop != NULL) Xfree ((char *)prop);
return False;
}
hints->flags = prop->flags;
/* XSizeHints misdeclares these as int instead of long */
hints->x = cvtINT32toInt (prop->x);
hints->y = cvtINT32toInt (prop->y);
hints->width = cvtINT32toInt (prop->width);
hints->height = cvtINT32toInt (prop->height);
hints->min_width = cvtINT32toInt (prop->minWidth);
hints->min_height = cvtINT32toInt (prop->minHeight);
hints->max_width = cvtINT32toInt (prop->maxWidth);
hints->max_height = cvtINT32toInt (prop->maxHeight);
hints->width_inc = cvtINT32toInt (prop->widthInc);
hints->height_inc = cvtINT32toInt (prop->heightInc);
hints->min_aspect.x = cvtINT32toInt (prop->minAspectX);
hints->min_aspect.y = cvtINT32toInt (prop->minAspectY);
hints->max_aspect.x = cvtINT32toInt (prop->maxAspectX);
hints->max_aspect.y = cvtINT32toInt (prop->maxAspectY);
*supplied = (USPosition | USSize | PAllHints);
if (nitems >= NumPropSizeElements) {
hints->base_width= cvtINT32toInt (prop->baseWidth);
hints->base_height= cvtINT32toInt (prop->baseHeight);
hints->win_gravity= cvtINT32toInt (prop->winGravity);
*supplied |= (PBaseSize | PWinGravity);
}
hints->flags &= (*supplied); /* get rid of unwanted bits */
Xfree((char *)prop);
return True;
}
Status XGetWMNormalHints (
Display *dpy,
Window w,
XSizeHints *hints,
long *supplied)
{
return (XGetWMSizeHints (dpy, w, hints, supplied, XA_WM_NORMAL_HINTS));
}
|
astrangeguy/libx11-debian-mirror
|
src/Window.c
|
/*
Copyright 1986, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
void _XProcessWindowAttributes (
register Display *dpy,
xChangeWindowAttributesReq *req,
register unsigned long valuemask,
register XSetWindowAttributes *attributes)
{
unsigned long values[32];
register unsigned long *value = values;
unsigned int nvalues;
if (valuemask & CWBackPixmap)
*value++ = attributes->background_pixmap;
if (valuemask & CWBackPixel)
*value++ = attributes->background_pixel;
if (valuemask & CWBorderPixmap)
*value++ = attributes->border_pixmap;
if (valuemask & CWBorderPixel)
*value++ = attributes->border_pixel;
if (valuemask & CWBitGravity)
*value++ = attributes->bit_gravity;
if (valuemask & CWWinGravity)
*value++ = attributes->win_gravity;
if (valuemask & CWBackingStore)
*value++ = attributes->backing_store;
if (valuemask & CWBackingPlanes)
*value++ = attributes->backing_planes;
if (valuemask & CWBackingPixel)
*value++ = attributes->backing_pixel;
if (valuemask & CWOverrideRedirect)
*value++ = attributes->override_redirect;
if (valuemask & CWSaveUnder)
*value++ = attributes->save_under;
if (valuemask & CWEventMask)
*value++ = attributes->event_mask;
if (valuemask & CWDontPropagate)
*value++ = attributes->do_not_propagate_mask;
if (valuemask & CWColormap)
*value++ = attributes->colormap;
if (valuemask & CWCursor)
*value++ = attributes->cursor;
req->length += (nvalues = value - values);
nvalues <<= 2; /* watch out for macros... */
Data32 (dpy, (long *) values, (long)nvalues);
}
#define AllMaskBits (CWBackPixmap|CWBackPixel|CWBorderPixmap|\
CWBorderPixel|CWBitGravity|CWWinGravity|\
CWBackingStore|CWBackingPlanes|CWBackingPixel|\
CWOverrideRedirect|CWSaveUnder|CWEventMask|\
CWDontPropagate|CWColormap|CWCursor)
Window XCreateWindow(
register Display *dpy,
Window parent,
int x,
int y,
unsigned int width,
unsigned int height,
unsigned int borderWidth,
int depth,
unsigned int class,
Visual *visual,
unsigned long valuemask,
XSetWindowAttributes *attributes)
{
Window wid;
register xCreateWindowReq *req;
LockDisplay(dpy);
GetReq(CreateWindow, req);
req->parent = parent;
req->x = x;
req->y = y;
req->width = width;
req->height = height;
req->borderWidth = borderWidth;
req->depth = depth;
req->class = class;
if (visual == CopyFromParent)
req->visual = CopyFromParent;
else
req->visual = visual->visualid;
wid = req->wid = XAllocID(dpy);
valuemask &= AllMaskBits;
if ((req->mask = valuemask))
_XProcessWindowAttributes (dpy, (xChangeWindowAttributesReq *)req,
valuemask, attributes);
UnlockDisplay(dpy);
SyncHandle();
return (wid);
}
|
astrangeguy/libx11-debian-mirror
|
src/Xintatom.h
|
<reponame>astrangeguy/libx11-debian-mirror<filename>src/Xintatom.h
#ifndef _XINTATOM_H_
#define _XINTATOM_H_ 1
#include <X11/Xfuncproto.h>
/* IntAtom.c */
#define TABLESIZE 64
typedef struct _Entry {
unsigned long sig;
Atom atom;
} EntryRec, *Entry;
#define RESERVED ((Entry) 1)
#define EntryName(e) ((char *)(e+1))
typedef struct _XDisplayAtoms {
Entry table[TABLESIZE];
} AtomTable;
_XFUNCPROTOBEGIN
extern void _XUpdateAtomCache(Display *dpy, const char *name, Atom atom,
unsigned long sig, int idx, int n);
extern void _XFreeAtomTable(Display *dpy);
_XFUNCPROTOEND
#endif /* _XINTATOM_H_ */
|
astrangeguy/libx11-debian-mirror
|
src/xkb/XKBList.c
|
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#define NEED_MAP_READERS
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include "XKBlibint.h"
/***====================================================================***/
static void
_FreeComponentNames(int num,XkbComponentNamePtr names)
{
int i;
XkbComponentNamePtr tmp;
if ((num<1)||(names==NULL))
return;
for (i=0,tmp=names;i<num;i++,tmp++) {
if (tmp->name) {
_XkbFree(tmp->name);
tmp->name= NULL;
}
}
_XkbFree(names);
return;
}
/***====================================================================***/
static XkbComponentNamePtr
_ReadListing(XkbReadBufferPtr buf,int count,Status *status_rtrn)
{
XkbComponentNamePtr first,this;
register int i;
CARD16 * flags;
int slen,wlen;
char * str;
if (count<1)
return NULL;
first= _XkbTypedCalloc(count,XkbComponentNameRec);
if (!first)
return NULL;
for (this=first,i=0;i<count;i++,this++) {
flags= (CARD16 *)_XkbGetReadBufferPtr(buf,2*sizeof(CARD16));
if (!flags)
goto BAILOUT;
this->flags= flags[0];
slen= flags[1];
wlen= ((slen+1)/2)*2; /* pad to 2 byte boundary */
this->name= _XkbTypedCalloc(slen+1,char);
if (!this->name)
goto BAILOUT;
str= (char *)_XkbGetReadBufferPtr(buf,wlen);
if (!str)
goto BAILOUT;
memcpy(this->name,str,slen);
}
return first;
BAILOUT:
*status_rtrn= BadAlloc;
_FreeComponentNames(i,first);
return NULL;
}
/***====================================================================***/
XkbComponentListPtr
XkbListComponents( Display * dpy,
unsigned deviceSpec,
XkbComponentNamesPtr ptrns,
int * max_inout)
{
register xkbListComponentsReq* req;
xkbListComponentsReply rep;
XkbInfoPtr xkbi;
XkbComponentListPtr list;
XkbReadBufferRec buf;
int left;
char * str;
int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen;
if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
(ptrns==NULL) || (max_inout==NULL))
return NULL;
xkbi= dpy->xkb_info;
LockDisplay(dpy);
GetReq(kbListComponents, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbListComponents;
req->deviceSpec = deviceSpec;
req->maxNames = *max_inout;
mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
if (ptrns->keymap)
mapLen= (int)strlen(ptrns->keymap);
if (ptrns->keycodes)
codesLen= (int)strlen(ptrns->keycodes);
if (ptrns->types)
typesLen= (int)strlen(ptrns->types);
if (ptrns->compat)
compatLen= (int)strlen(ptrns->compat);
if (ptrns->symbols)
symsLen= (int)strlen(ptrns->symbols);
if (ptrns->geometry)
geomLen= (int)strlen(ptrns->geometry);
if (mapLen>255) mapLen= 255;
if (codesLen>255) codesLen= 255;
if (typesLen>255) typesLen= 255;
if (compatLen>255) compatLen= 255;
if (symsLen>255) symsLen= 255;
if (geomLen>255) geomLen= 255;
len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
len= XkbPaddedSize(len);
req->length+= len/4;
BufAlloc(char *,str,len);
*str++= mapLen;
if (mapLen>0) {
memcpy(str,ptrns->keymap,mapLen);
str+= mapLen;
}
*str++= codesLen;
if (codesLen>0) {
memcpy(str,ptrns->keycodes,codesLen);
str+= codesLen;
}
*str++= typesLen;
if (typesLen>0) {
memcpy(str,ptrns->types,typesLen);
str+= typesLen;
}
*str++= compatLen;
if (compatLen>0) {
memcpy(str,ptrns->compat,compatLen);
str+= compatLen;
}
*str++= symsLen;
if (symsLen>0) {
memcpy(str,ptrns->symbols,symsLen);
str+= symsLen;
}
*str++= geomLen;
if (geomLen>0) {
memcpy(str,ptrns->geometry,geomLen);
str+= geomLen;
}
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
goto BAILOUT;
extraLen= (int)rep.length*4;
*max_inout= rep.extra;
if (extraLen==0) { /* no matches, but we don't want to report a failure */
list= _XkbTypedCalloc(1,XkbComponentListRec);
UnlockDisplay(dpy);
SyncHandle();
return list;
}
if (_XkbInitReadBuffer(dpy,&buf,extraLen)) {
Status status;
status= Success;
list= _XkbTypedCalloc(1,XkbComponentListRec);
if (!list) {
_XkbFreeReadBuffer(&buf);
goto BAILOUT;
}
list->num_keymaps= rep.nKeymaps;
list->num_keycodes= rep.nKeycodes;
list->num_types= rep.nTypes;
list->num_compat= rep.nCompatMaps;
list->num_symbols= rep.nSymbols;
list->num_geometry= rep.nGeometries;
if ((status==Success)&&(list->num_keymaps>0))
list->keymaps= _ReadListing(&buf,list->num_keymaps,&status);
if ((status==Success)&&(list->num_keycodes>0))
list->keycodes= _ReadListing(&buf,list->num_keycodes,&status);
if ((status==Success)&&(list->num_types>0))
list->types= _ReadListing(&buf,list->num_types,&status);
if ((status==Success)&&(list->num_compat>0))
list->compat= _ReadListing(&buf,list->num_compat,&status);
if ((status==Success)&&(list->num_symbols>0))
list->symbols= _ReadListing(&buf,list->num_symbols,&status);
if ((status==Success)&&(list->num_geometry>0))
list->geometry= _ReadListing(&buf,list->num_geometry,&status);
left= _XkbFreeReadBuffer(&buf);
if ((status!=Success)||(buf.error)||(left>2)) {
XkbFreeComponentList(list);
goto BAILOUT;
}
UnlockDisplay(dpy);
SyncHandle();
return list;
}
BAILOUT:
UnlockDisplay(dpy);
SyncHandle();
return NULL;
}
void
XkbFreeComponentList(XkbComponentListPtr list)
{
if (list) {
if (list->keymaps)
_FreeComponentNames(list->num_keymaps,list->keymaps);
if (list->keycodes)
_FreeComponentNames(list->num_keycodes,list->keycodes);
if (list->types)
_FreeComponentNames(list->num_types,list->types);
if (list->compat)
_FreeComponentNames(list->num_compat,list->compat);
if (list->symbols)
_FreeComponentNames(list->num_symbols,list->symbols);
if (list->geometry)
_FreeComponentNames(list->num_geometry,list->geometry);
bzero((char *)list,sizeof(XkbComponentListRec));
_XkbFree(list);
}
return;
}
|
astrangeguy/libx11-debian-mirror
|
src/GetMoEv.c
|
/*
Copyright 1986, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
XTimeCoord *XGetMotionEvents(
register Display *dpy,
Window w,
Time start,
Time stop,
int *nEvents) /* RETURN */
{
xGetMotionEventsReply rep;
register xGetMotionEventsReq *req;
XTimeCoord *tc = NULL;
long nbytes;
LockDisplay(dpy);
GetReq(GetMotionEvents, req);
req->window = w;
/* XXX is this right for all machines? */
req->start = start;
req->stop = stop;
if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return (NULL);
}
if (rep.nEvents) {
if (! (tc = (XTimeCoord *)
Xmalloc( (unsigned)
(nbytes = (long) rep.nEvents * sizeof(XTimeCoord))))) {
_XEatData (dpy, (unsigned long) nbytes);
UnlockDisplay(dpy);
SyncHandle();
return (NULL);
}
}
*nEvents = rep.nEvents;
nbytes = SIZEOF (xTimecoord);
{
register XTimeCoord *tcptr;
register int i;
xTimecoord xtc;
for (i = rep.nEvents, tcptr = tc; i > 0; i--, tcptr++) {
_XRead (dpy, (char *) &xtc, nbytes);
tcptr->time = xtc.time;
tcptr->x = cvtINT16toShort (xtc.x);
tcptr->y = cvtINT16toShort (xtc.y);
}
}
UnlockDisplay(dpy);
SyncHandle();
return (tc);
}
|
astrangeguy/libx11-debian-mirror
|
src/ErrDes.c
|
/*
*/
/***********************************************************
Copyright 1987, 1988, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include <X11/Xos.h>
#include "Xresource.h"
#include <stdio.h>
#ifndef ERRORDB
#ifndef XERRORDB
#define ERRORDB "/usr/lib/X11/XErrorDB"
#else
#define ERRORDB XERRORDB
#endif
#endif
/*
* descriptions of errors in Section 4 of Protocol doc (pp. 350-351); more
* verbose descriptions are given in the error database
*/
static const char _XErrorList[] =
/* No error */ "no error\0"
/* BadRequest */ "BadRequest\0"
/* BadValue */ "BadValue\0"
/* BadWindow */ "BadWindow\0"
/* BadPixmap */ "BadPixmap\0"
/* BadAtom */ "BadAtom\0"
/* BadCursor */ "BadCursor\0"
/* BadFont */ "BadFont\0"
/* BadMatch */ "BadMatch\0"
/* BadDrawable */ "BadDrawable\0"
/* BadAccess */ "BadAccess\0"
/* BadAlloc */ "BadAlloc\0"
/* BadColor */ "BadColor\0"
/* BadGC */ "BadGC\0"
/* BadIDChoice */ "BadIDChoice\0"
/* BadName */ "BadName\0"
/* BadLength */ "BadLength\0"
/* BadImplementation */ "BadImplementation"
;
/* offsets into _XErrorList */
static const unsigned char _XErrorOffsets[] = {
0, 9, 20, 29, 39, 49, 57, 67, 75, 84, 96,
106, 115, 124, 130, 142, 150, 160
};
int
XGetErrorText(
register Display *dpy,
register int code,
char *buffer,
int nbytes)
{
char buf[150];
register _XExtension *ext;
_XExtension *bext = (_XExtension *)NULL;
if (nbytes == 0) return 0;
if (code <= BadImplementation && code > 0) {
sprintf(buf, "%d", code);
(void) XGetErrorDatabaseText(dpy, "XProtoError", buf,
_XErrorList + _XErrorOffsets[code],
buffer, nbytes);
} else
buffer[0] = '\0';
/* call out to any extensions interested */
for (ext = dpy->ext_procs; ext; ext = ext->next) {
if (ext->error_string)
(*ext->error_string)(dpy, code, &ext->codes, buffer, nbytes);
if (ext->codes.first_error &&
ext->codes.first_error <= code &&
(!bext || ext->codes.first_error > bext->codes.first_error))
bext = ext;
}
if (!buffer[0] && bext) {
sprintf(buf, "%s.%d", bext->name, code - bext->codes.first_error);
(void) XGetErrorDatabaseText(dpy, "XProtoError", buf, "", buffer, nbytes);
}
if (!buffer[0])
sprintf(buffer, "%d", code);
return 0;
}
int
/*ARGSUSED*/
XGetErrorDatabaseText(
Display *dpy,
register _Xconst char *name,
register _Xconst char *type,
_Xconst char *defaultp,
char *buffer,
int nbytes)
{
static XrmDatabase db = NULL;
XrmString type_str;
XrmValue result;
char temp[BUFSIZ];
char* tptr;
unsigned long tlen;
if (nbytes == 0) return 0;
if (!db) {
/* the Xrm routines expect to be called with the global
mutex unlocked. */
XrmDatabase temp_db;
int do_destroy;
const char *dbname;
XrmInitialize();
#ifdef WIN32
dbname = getenv("XERRORDB");
if (!dbname)
dbname = ERRORDB;
#else
dbname = ERRORDB;
#endif
temp_db = XrmGetFileDatabase(dbname);
_XLockMutex(_Xglobal_lock);
if (!db) {
db = temp_db;
do_destroy = 0;
} else
do_destroy = 1; /* we didn't need to get it after all */
_XUnlockMutex(_Xglobal_lock);
if (do_destroy)
XrmDestroyDatabase(temp_db);
}
if (db)
{
tlen = strlen (name) + strlen (type) + 2;
if (tlen <= sizeof(temp))
tptr = temp;
else
tptr = Xmalloc (tlen);
if (tptr) {
sprintf(tptr, "%s.%s", name, type);
XrmGetResource(db, tptr, "ErrorType.ErrorNumber",
&type_str, &result);
if (tptr != temp)
Xfree (tptr);
} else {
result.addr = (XPointer) NULL;
}
}
else
result.addr = (XPointer)NULL;
if (!result.addr) {
result.addr = (XPointer) defaultp;
result.size = strlen(defaultp) + 1;
}
(void) strncpy (buffer, (char *) result.addr, nbytes);
if (result.size > nbytes) buffer[nbytes-1] = '\0';
return 0;
}
|
astrangeguy/libx11-debian-mirror
|
modules/im/ximcp/imThaiIm.c
|
<gh_stars>0
/******************************************************************
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
Copyright 1993 by Digital Equipment Corporation
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of FUJITSU LIMITED and
Digital Equipment Corporation not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission. FUJITSU LIMITED and Digital Equipment Corporation
makes no representations about the suitability of this software for
any purpose. It is provided "as is" without express or implied
warranty.
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
Author: <NAME> FUJITSU LIMITED
<EMAIL>
Modifier: <NAME> Digital Equipment Corporation
<EMAIL>
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xmd.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "XlcPublic.h"
#include "XlcPubI.h"
#include "Ximint.h"
Private XIMMethodsRec Xim_im_thai_methods = {
_XimThaiCloseIM, /* close */
_XimLocalSetIMValues, /* set_values */
_XimLocalGetIMValues, /* get_values */
_XimThaiCreateIC, /* create_ic */
_XimLcctstombs, /* ctstombs */
_XimLcctstowcs, /* ctstowcs */
_XimLcctstoutf8 /* ctstoutf8 */
};
#define THAI_LANGUAGE_NAME "th"
Bool
_XimCheckIfThaiProcessing(Xim im)
{
char *language;
_XGetLCValues(im->core.lcd, XlcNLanguage, &language, NULL);
if(strcmp(language, THAI_LANGUAGE_NAME) == 0 &&
(strcmp(im->core.im_name, "") == 0 ||
strcmp(im->core.im_name, "BasicCheck") == 0 ||
strcmp(im->core.im_name, "Strict") == 0 ||
strcmp(im->core.im_name, "Thaicat") == 0 ||
strcmp(im->core.im_name, "Passthrough") == 0))
{
return(True);
}
return(False);
}
Public Bool
_XimThaiOpenIM(Xim im)
{
XLCd lcd = im->core.lcd;
XlcConv conv;
XimDefIMValues im_values;
XimLocalPrivateRec* private = &im->private.local;
_XimInitialResourceInfo();
if(_XimSetIMResourceList(&im->core.im_resources,
&im->core.im_num_resources) == False) {
goto Open_Error;
}
if(_XimSetICResourceList(&im->core.ic_resources,
&im->core.ic_num_resources) == False) {
goto Open_Error;
}
_XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
_XimGetCurrentIMValues(im, &im_values);
if(_XimSetLocalIMDefaults(im, (XPointer)&im_values,
im->core.im_resources, im->core.im_num_resources) == False) {
goto Open_Error;
}
_XimSetCurrentIMValues(im, &im_values);
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte)))
goto Open_Error;
private->ctom_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar)))
goto Open_Error;
private->ctow_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String)))
goto Open_Error;
private->ctoutf8_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
goto Open_Error;
private->cstomb_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
goto Open_Error;
private->cstowc_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
goto Open_Error;
private->cstoutf8_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
goto Open_Error;
private->ucstoc_conv = conv;
if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
goto Open_Error;
private->ucstoutf8_conv = conv;
im->methods = &Xim_im_thai_methods;
private->current_ic = (XIC)NULL;
return(True);
Open_Error :
_XimThaiIMFree(im);
return(False);
}
Public void
_XimThaiIMFree(Xim im)
{
if(im->core.im_resources) {
Xfree(im->core.im_resources);
im->core.im_resources = NULL;
}
if(im->core.ic_resources) {
Xfree(im->core.ic_resources);
im->core.ic_resources = NULL;
}
if(im->core.im_values_list) {
Xfree(im->core.im_values_list);
im->core.im_values_list = NULL;
}
if(im->core.ic_values_list) {
Xfree(im->core.ic_values_list);
im->core.ic_values_list = NULL;
}
if(im->core.styles) {
Xfree(im->core.styles);
im->core.styles = NULL;
}
if(im->core.res_name) {
Xfree(im->core.res_name);
im->core.res_name = NULL;
}
if(im->core.res_class) {
Xfree(im->core.res_class);
im->core.res_class = NULL;
}
if(im->core.im_name) {
Xfree(im->core.im_name);
im->core.im_name = NULL;
}
if (im->private.local.ctom_conv) {
_XlcCloseConverter(im->private.local.ctom_conv);
im->private.local.ctom_conv = NULL;
}
if (im->private.local.ctow_conv) {
_XlcCloseConverter(im->private.local.ctow_conv);
im->private.local.ctow_conv = NULL;
}
if (im->private.local.ctoutf8_conv) {
_XlcCloseConverter(im->private.local.ctoutf8_conv);
im->private.local.ctoutf8_conv = NULL;
}
if (im->private.local.cstomb_conv) {
_XlcCloseConverter(im->private.local.cstomb_conv);
im->private.local.cstomb_conv = NULL;
}
if (im->private.local.cstowc_conv) {
_XlcCloseConverter(im->private.local.cstowc_conv);
im->private.local.cstowc_conv = NULL;
}
if (im->private.local.cstoutf8_conv) {
_XlcCloseConverter(im->private.local.cstoutf8_conv);
im->private.local.cstoutf8_conv = NULL;
}
if (im->private.local.ucstoc_conv) {
_XlcCloseConverter(im->private.local.ucstoc_conv);
im->private.local.ucstoc_conv = NULL;
}
if (im->private.local.ucstoutf8_conv) {
_XlcCloseConverter(im->private.local.ucstoutf8_conv);
im->private.local.ucstoutf8_conv = NULL;
}
return;
}
Public Status
_XimThaiCloseIM(XIM xim)
{
Xim im = (Xim)xim;
XIC ic;
XIC next;
ic = im->core.ic_chain;
im->core.ic_chain = NULL;
while (ic) {
(*ic->methods->destroy) (ic);
next = ic->core.next;
Xfree ((char *) ic);
ic = next;
}
_XimThaiIMFree(im);
return(True);
}
|
astrangeguy/libx11-debian-mirror
|
modules/im/ximcp/imDefLkup.c
|
/******************************************************************
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation, and that the name of FUJITSU LIMITED
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission.
FUJITSU LIMITED makes no representations about the suitability of
this software for any purpose.
It is provided "as is" without express or implied warranty.
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Author: <NAME> FUJITSU LIMITED
<EMAIL>
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/Xatom.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "Ximint.h"
Public Xic
_XimICOfXICID(
Xim im,
XICID icid)
{
Xic pic;
for (pic = (Xic)im->core.ic_chain; pic; pic = (Xic)pic->core.next) {
if (pic->private.proto.icid == icid)
return pic;
}
return (Xic)0;
}
Private void
_XimProcIMSetEventMask(
Xim im,
XPointer buf)
{
EVENTMASK *buf_l = (EVENTMASK *)buf;
im->private.proto.forward_event_mask = buf_l[0];
im->private.proto.synchronous_event_mask = buf_l[1];
return;
}
Private void
_XimProcICSetEventMask(
Xic ic,
XPointer buf)
{
EVENTMASK *buf_l = (EVENTMASK *)buf;
ic->private.proto.forward_event_mask = buf_l[0];
ic->private.proto.synchronous_event_mask = buf_l[1];
_XimReregisterFilter(ic);
return;
}
Public Bool
_XimSetEventMaskCallback(
Xim xim,
INT16 len,
XPointer data,
XPointer call_data)
{
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
XIMID imid = buf_s[0];
XICID icid = buf_s[1];
Xim im = (Xim)call_data;
Xic ic;
if (imid == im->private.proto.imid) {
if (icid) {
ic = _XimICOfXICID(im, icid);
_XimProcICSetEventMask(ic, (XPointer)&buf_s[2]);
} else {
_XimProcIMSetEventMask(im, (XPointer)&buf_s[2]);
}
return True;
}
return False;
}
Private Bool
_XimSyncCheck(
Xim im,
INT16 len,
XPointer data,
XPointer arg)
{
Xic ic = (Xic)arg;
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
CARD8 major_opcode = *((CARD8 *)data);
CARD8 minor_opcode = *((CARD8 *)data + 1);
XIMID imid = buf_s[0];
XICID icid = buf_s[1];
if ((major_opcode == XIM_SYNC_REPLY)
&& (minor_opcode == 0)
&& (imid == im->private.proto.imid)
&& (icid == ic->private.proto.icid))
return True;
if ((major_opcode == XIM_ERROR)
&& (minor_opcode == 0)
&& (buf_s[2] & XIM_IMID_VALID)
&& (imid == im->private.proto.imid)
&& (buf_s[2] & XIM_ICID_VALID)
&& (icid == ic->private.proto.icid))
return True;
return False;
}
Public Bool
_XimSync(
Xim im,
Xic ic)
{
CARD32 buf32[BUFSIZE/4];
CARD8 *buf = (CARD8 *)buf32;
CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
INT16 len;
CARD32 reply32[BUFSIZE/4];
char *reply = (char *)reply32;
XPointer preply;
int buf_size;
int ret_code;
buf_s[0] = im->private.proto.imid; /* imid */
buf_s[1] = ic->private.proto.icid; /* icid */
len = sizeof(CARD16) /* sizeof imid */
+ sizeof(CARD16); /* sizeof icid */
_XimSetHeader((XPointer)buf, XIM_SYNC, 0, &len);
if (!(_XimWrite(im, len, (XPointer)buf)))
return False;
_XimFlush(im);
buf_size = BUFSIZE;
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
_XimSyncCheck, (XPointer)ic);
if(ret_code == XIM_TRUE) {
preply = reply;
} else if(ret_code == XIM_OVERFLOW) {
if(len <= 0) {
preply = reply;
} else {
buf_size = len;
preply = (XPointer)Xmalloc(len);
ret_code = _XimRead(im, &len, preply, buf_size,
_XimSyncCheck, (XPointer)ic);
if(ret_code != XIM_TRUE) {
Xfree(preply);
return False;
}
}
} else {
return False;
}
buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
if (*((CARD8 *)preply) == XIM_ERROR) {
_XimProcError(im, 0, (XPointer)&buf_s[3]);
if(reply != preply)
Xfree(preply);
return False;
}
if(reply != preply)
Xfree(preply);
return True;
}
Public Bool
_XimProcSyncReply(
Xim im,
Xic ic)
{
CARD32 buf32[BUFSIZE/4];
CARD8 *buf = (CARD8 *)buf32;
CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
INT16 len;
buf_s[0] = im->private.proto.imid; /* imid */
buf_s[1] = ic->private.proto.icid; /* icid */
len = sizeof(CARD16) /* sizeof imid */
+ sizeof(CARD16); /* sizeof icid */
_XimSetHeader((XPointer)buf, XIM_SYNC_REPLY, 0, &len);
if (!(_XimWrite(im, len, (XPointer)buf)))
return False;
_XimFlush(im);
return True;
}
Public Bool
_XimRespSyncReply(
Xic ic,
BITMASK16 mode)
{
if (mode & XimSYNCHRONUS) /* SYNC Request */
MARK_NEED_SYNC_REPLY(ic->core.im);
return True;
}
Public Bool
_XimSyncCallback(
Xim xim,
INT16 len,
XPointer data,
XPointer call_data)
{
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
XIMID imid = buf_s[0];
XICID icid = buf_s[1];
Xim im = (Xim)call_data;
Xic ic;
if ((imid == im->private.proto.imid)
&& (ic = _XimICOfXICID(im, icid))) {
(void)_XimProcSyncReply(im, ic);
return True;
}
return False;
}
Private INT16
_XimSetEventToWire(
XEvent *ev,
xEvent *event)
{
if (!(_XimProtoEventToWire(ev, event, False)))
return 0;
event->u.u.sequenceNumber =
((XAnyEvent *)ev)->serial & (unsigned long)0xffff;
return sz_xEvent;
}
Private Bool
_XimForwardEventCore(
Xic ic,
XEvent *ev,
Bool sync)
{
Xim im = (Xim)ic->core.im;
CARD32 buf32[BUFSIZE/4];
CARD8 *buf = (CARD8 *)buf32;
CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
CARD32 reply32[BUFSIZE/4];
char *reply = (char *)reply32;
XPointer preply;
int buf_size;
int ret_code;
INT16 len;
if (!(len = _XimSetEventToWire(ev, (xEvent *)&buf_s[4])))
return False; /* X event */
buf_s[0] = im->private.proto.imid; /* imid */
buf_s[1] = ic->private.proto.icid; /* icid */
buf_s[2] = sync ? XimSYNCHRONUS : 0; /* flag */
buf_s[3] =
(CARD16)((((XAnyEvent *)ev)->serial & ~((unsigned long)0xffff)) >> 16);
/* serial number */
len += sizeof(CARD16) /* sizeof imid */
+ sizeof(CARD16) /* sizeof icid */
+ sizeof(BITMASK16) /* sizeof flag */
+ sizeof(CARD16); /* sizeof serila number */
_XimSetHeader((XPointer)buf, XIM_FORWARD_EVENT, 0, &len);
if (!(_XimWrite(im, len, (XPointer)buf)))
return False;
_XimFlush(im);
if (sync) {
buf_size = BUFSIZE;
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
_XimSyncCheck, (XPointer)ic);
if(ret_code == XIM_TRUE) {
preply = reply;
} else if(ret_code == XIM_OVERFLOW) {
if(len <= 0) {
preply = reply;
} else {
buf_size = len;
preply = (XPointer)Xmalloc(len);
ret_code = _XimRead(im, &len, preply, buf_size,
_XimSyncCheck, (XPointer)ic);
if(ret_code != XIM_TRUE) {
Xfree(preply);
return False;
}
}
} else {
return False;
}
buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
if (*((CARD8 *)preply) == XIM_ERROR) {
_XimProcError(im, 0, (XPointer)&buf_s[3]);
if(reply != preply)
Xfree(preply);
return False;
}
if(reply != preply)
Xfree(preply);
}
return True;
}
Public Bool
_XimForwardEvent(
Xic ic,
XEvent *ev,
Bool sync)
{
#ifdef EXT_FORWARD
if (((ev->type == KeyPress) || (ev->type == KeyRelease)))
if (_XimExtForwardKeyEvent(ic, (XKeyEvent *)ev, sync))
return True;
#endif
return _XimForwardEventCore(ic, ev, sync);
}
Private void
_XimProcEvent(
Display *d,
Xic ic,
XEvent *ev,
CARD16 *buf)
{
INT16 serial = buf[0];
xEvent *xev = (xEvent *)&buf[1];
_XimProtoWireToEvent(ev, xev, False);
ev->xany.serial |= serial << 16;
ev->xany.send_event = False;
ev->xany.display = d;
MARK_FABRICATED(ic->core.im);
return;
}
Private Bool
_XimForwardEventRecv(
Xim im,
Xic ic,
XPointer buf)
{
CARD16 *buf_s = (CARD16 *)buf;
Display *d = im->core.display;
XEvent ev;
_XimProcEvent(d, ic, &ev, &buf_s[1]);
(void)_XimRespSyncReply(ic, buf_s[0]);
XPutBackEvent(d, &ev);
return True;
}
Public Bool
_XimForwardEventCallback(
Xim xim,
INT16 len,
XPointer data,
XPointer call_data)
{
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
XIMID imid = buf_s[0];
XICID icid = buf_s[1];
Xim im = (Xim)call_data;
Xic ic;
if ((imid == im->private.proto.imid)
&& (ic = _XimICOfXICID(im, icid))) {
(void)_XimForwardEventRecv(im, ic, (XPointer)&buf_s[2]);
return True;
}
return False;
}
Private Bool
_XimRegisterTriggerkey(
Xim im,
XPointer buf)
{
CARD32 *buf_l = (CARD32 *)buf;
CARD32 len;
CARD32 *key;
if (IS_DYNAMIC_EVENT_FLOW(im)) /* already Dynamic event flow mode */
return True;
/*
* register onkeylist
*/
len = buf_l[0]; /* length of on-keys */
len += sizeof(INT32); /* sizeof length of on-keys */
if (!(key = (CARD32 *)Xmalloc(len))) {
_XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
return False;
}
memcpy((char *)key, (char *)buf_l, len);
im->private.proto.im_onkeylist = key;
MARK_DYNAMIC_EVENT_FLOW(im);
/*
* register offkeylist
*/
buf_l = (CARD32 *)((char *)buf + len);
len = buf_l[0]; /* length of off-keys */
len += sizeof(INT32); /* sizeof length of off-keys */
if (!(key = (CARD32 *)Xmalloc(len))) {
_XimError(im, 0, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
return False;
}
memcpy((char *)key, (char *)buf_l, len);
im->private.proto.im_offkeylist = key;
return True;
}
Public Bool
_XimRegisterTriggerKeysCallback(
Xim xim,
INT16 len,
XPointer data,
XPointer call_data)
{
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
Xim im = (Xim)call_data;
(void )_XimRegisterTriggerkey(im, (XPointer)&buf_s[2]);
return True;
}
Public EVENTMASK
_XimGetWindowEventmask(
Xic ic)
{
Xim im = (Xim )ic->core.im;
XWindowAttributes atr;
if (!XGetWindowAttributes(im->core.display, ic->core.focus_window, &atr))
return 0;
return (EVENTMASK)atr.your_event_mask;
}
Private Bool
_XimTriggerNotifyCheck(
Xim im,
INT16 len,
XPointer data,
XPointer arg)
{
Xic ic = (Xic)arg;
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
CARD8 major_opcode = *((CARD8 *)data);
CARD8 minor_opcode = *((CARD8 *)data + 1);
XIMID imid = buf_s[0];
XICID icid = buf_s[1];
if ((major_opcode == XIM_TRIGGER_NOTIFY_REPLY)
&& (minor_opcode == 0)
&& (imid == im->private.proto.imid)
&& (icid == ic->private.proto.icid))
return True;
if ((major_opcode == XIM_ERROR)
&& (minor_opcode == 0)
&& (buf_s[2] & XIM_IMID_VALID)
&& (imid == im->private.proto.imid)
&& (buf_s[2] & XIM_ICID_VALID)
&& (icid == ic->private.proto.icid))
return True;
return False;
}
Public Bool
_XimTriggerNotify(
Xim im,
Xic ic,
int mode,
CARD32 idx)
{
CARD32 buf32[BUFSIZE/4];
CARD8 *buf = (CARD8 *)buf32;
CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
CARD32 *buf_l = (CARD32 *)&buf[XIM_HEADER_SIZE];
CARD32 reply32[BUFSIZE/4];
char *reply = (char *)reply32;
XPointer preply;
int buf_size;
int ret_code;
INT16 len;
EVENTMASK mask = _XimGetWindowEventmask(ic);
buf_s[0] = im->private.proto.imid; /* imid */
buf_s[1] = ic->private.proto.icid; /* icid */
buf_l[1] = mode; /* flag */
buf_l[2] = idx; /* index of keys list */
buf_l[3] = mask; /* select-event-mask */
len = sizeof(CARD16) /* sizeof imid */
+ sizeof(CARD16) /* sizeof icid */
+ sizeof(CARD32) /* sizeof flag */
+ sizeof(CARD32) /* sizeof index of key list */
+ sizeof(EVENTMASK); /* sizeof select-event-mask */
_XimSetHeader((XPointer)buf, XIM_TRIGGER_NOTIFY, 0, &len);
if (!(_XimWrite(im, len, (XPointer)buf)))
return False;
_XimFlush(im);
buf_size = BUFSIZE;
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
_XimTriggerNotifyCheck, (XPointer)ic);
if(ret_code == XIM_TRUE) {
preply = reply;
} else if(ret_code == XIM_OVERFLOW) {
if(len <= 0) {
preply = reply;
} else {
buf_size = len;
preply = (XPointer)Xmalloc(len);
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
_XimTriggerNotifyCheck, (XPointer)ic);
if(ret_code != XIM_TRUE) {
Xfree(preply);
return False;
}
}
} else {
return False;
}
buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
if (*((CARD8 *)preply) == XIM_ERROR) {
_XimProcError(im, 0, (XPointer)&buf_s[3]);
if(reply != preply)
Xfree(preply);
return False;
}
if(reply != preply)
Xfree(preply);
return True;
}
Private Bool
_XimRegCommitInfo(
Xic ic,
char *string,
int string_len,
KeySym *keysym,
int keysym_len)
{
XimCommitInfo info;
if (!(info = (XimCommitInfo)Xmalloc(sizeof(XimCommitInfoRec))))
return False;
info->string = string;
info->string_len = string_len;
info->keysym = keysym;
info->keysym_len = keysym_len;
info->next = ic->private.proto.commit_info;
ic->private.proto.commit_info = info;
return True;
}
Private void
_XimUnregCommitInfo(
Xic ic)
{
XimCommitInfo info;
if (!(info = ic->private.proto.commit_info))
return;
if (info->string)
Xfree(info->string);
if (info->keysym)
Xfree(info->keysym);
ic->private.proto.commit_info = info->next;
Xfree(info);
return;
}
Public void
_XimFreeCommitInfo(
Xic ic)
{
while (ic->private.proto.commit_info)
_XimUnregCommitInfo(ic);
return;
}
Private Bool
_XimProcKeySym(
Xic ic,
CARD32 sym,
KeySym **xim_keysym,
int *xim_keysym_len)
{
Xim im = (Xim)ic->core.im;
if (!(*xim_keysym = (KeySym *)Xmalloc(sizeof(KeySym)))) {
_XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
return False;
}
**xim_keysym = (KeySym)sym;
*xim_keysym_len = 1;
return True;
}
Private Bool
_XimProcCommit(
Xic ic,
BYTE *buf,
int len,
char **xim_string,
int *xim_string_len)
{
Xim im = (Xim)ic->core.im;
char *string;
if (!(string = (char *)Xmalloc(len + 1))) {
_XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
return False;
}
(void)memcpy(string, (char *)buf, len);
string[len] = '\0';
*xim_string = string;
*xim_string_len = len;
return True;
}
Private Bool
_XimCommitRecv(
Xim im,
Xic ic,
XPointer buf)
{
CARD16 *buf_s = (CARD16 *)buf;
BITMASK16 flag = buf_s[0];
XKeyEvent ev;
char *string = NULL;
int string_len = 0;
KeySym *keysym = NULL;
int keysym_len = 0;
if ((flag & XimLookupBoth) == XimLookupChars) {
if (!(_XimProcCommit(ic, (BYTE *)&buf_s[2],
(int)buf_s[1], &string, &string_len)))
return False;
} else if ((flag & XimLookupBoth) == XimLookupKeySym) {
if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len)))
return False;
} else if ((flag & XimLookupBoth) == XimLookupBoth) {
if (!(_XimProcKeySym(ic, *(CARD32 *)&buf_s[2], &keysym, &keysym_len)))
return False;
if (!(_XimProcCommit(ic, (BYTE *)&buf_s[5],
(int)buf_s[4], &string, &string_len))) {
Xfree(keysym);
return False;
}
}
if (!(_XimRegCommitInfo(ic, string, string_len, keysym, keysym_len))) {
if (string)
Xfree(string);
if (keysym)
Xfree(keysym);
_XimError(im, ic, XIM_BadAlloc, (INT16)0, (CARD16)0, (char *)NULL);
return False;
}
(void)_XimRespSyncReply(ic, flag);
MARK_FABRICATED(im);
ev.type = KeyPress;
ev.send_event = False;
ev.display = im->core.display;
ev.window = ic->core.focus_window;
ev.keycode = 0;
ev.state = 0;
XPutBackEvent(im->core.display, (XEvent *)&ev);
return True;
}
Public Bool
_XimCommitCallback(
Xim xim,
INT16 len,
XPointer data,
XPointer call_data)
{
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
XIMID imid = buf_s[0];
XICID icid = buf_s[1];
Xim im = (Xim)call_data;
Xic ic;
if ((imid == im->private.proto.imid)
&& (ic = _XimICOfXICID(im, icid))) {
(void)_XimCommitRecv(im, ic, (XPointer)&buf_s[2]);
return True;
}
return False;
}
Public void
_XimProcError(
Xim im,
Xic ic,
XPointer data)
{
return;
}
Public Bool
_XimErrorCallback(
Xim xim,
INT16 len,
XPointer data,
XPointer call_data)
{
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
BITMASK16 flag = buf_s[2];
XIMID imid;
XICID icid;
Xim im = (Xim)call_data;
Xic ic = NULL;
if (flag & XIM_IMID_VALID) {
imid = buf_s[0];
if (imid != im->private.proto.imid)
return False;
}
if (flag & XIM_ICID_VALID) {
icid = buf_s[1];
if (!(ic = _XimICOfXICID(im, icid)))
return False;
}
_XimProcError(im, ic, (XPointer)&buf_s[3]);
return True;
}
Public Bool
_XimError(
Xim im,
Xic ic,
CARD16 error_code,
INT16 detail_length,
CARD16 type,
char *detail)
{
CARD32 buf32[BUFSIZE/4];
CARD8 *buf = (CARD8 *)buf32;
CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
INT16 len = 0;
buf_s[0] = im->private.proto.imid; /* imid */
buf_s[2] = XIM_IMID_VALID; /* flag */
if (ic) {
buf_s[1] = ic->private.proto.icid; /* icid */
buf_s[2] |= XIM_ICID_VALID; /* flag */
}
buf_s[3] = error_code; /* Error Code */
buf_s[4] = detail_length; /* length of error detail */
buf_s[5] = type; /* type of error detail */
if (detail_length && detail) {
len = detail_length;
memcpy((char *)&buf_s[6], detail, len);
XIM_SET_PAD(&buf_s[6], len);
}
len += sizeof(CARD16) /* sizeof imid */
+ sizeof(CARD16) /* sizeof icid */
+ sizeof(BITMASK16) /* sizeof flag */
+ sizeof(CARD16) /* sizeof error_code */
+ sizeof(INT16) /* sizeof length of detail */
+ sizeof(CARD16); /* sizeof type */
_XimSetHeader((XPointer)buf, XIM_ERROR, 0, &len);
if (!(_XimWrite(im, len, (XPointer)buf)))
return False;
_XimFlush(im);
return True;
}
Private int
_Ximctsconvert(
XlcConv conv,
char *from,
int from_len,
char *to,
int to_len,
Status *state)
{
int from_left;
int to_left;
int from_savelen;
int to_savelen;
int from_cnvlen;
int to_cnvlen;
char *from_buf;
char *to_buf;
char scratchbuf[BUFSIZ];
Status tmp_state;
if (!state)
state = &tmp_state;
if (!conv || !from || !from_len) {
*state = XLookupNone;
return 0;
}
/* Reset the converter. The CompoundText at 'from' starts in
initial state. */
_XlcResetConverter(conv);
from_left = from_len;
to_left = BUFSIZ;
from_cnvlen = 0;
to_cnvlen = 0;
for (;;) {
from_buf = &from[from_cnvlen];
from_savelen = from_left;
to_buf = &scratchbuf[to_cnvlen];
to_savelen = to_left;
if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
(XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
*state = XLookupNone;
return 0;
}
from_cnvlen += (from_savelen - from_left);
to_cnvlen += (to_savelen - to_left);
if (from_left == 0) {
if (!to_cnvlen) {
*state = XLookupNone;
return 0;
}
break;
}
}
if (!to || !to_len || (to_len < to_cnvlen)) {
*state = XBufferOverflow;
} else {
memcpy(to, scratchbuf, to_cnvlen);
*state = XLookupChars;
}
return to_cnvlen;
}
Public int
_Ximctstombs(XIM xim, char *from, int from_len,
char *to, int to_len, Status *state)
{
return _Ximctsconvert(((Xim)xim)->private.proto.ctom_conv,
from, from_len, to, to_len, state);
}
Public int
_Ximctstowcs(
XIM xim,
char *from,
int from_len,
wchar_t *to,
int to_len,
Status *state)
{
Xim im = (Xim)xim;
XlcConv conv = im->private.proto.ctow_conv;
int from_left;
int to_left;
int from_savelen;
int to_savelen;
int from_cnvlen;
int to_cnvlen;
char *from_buf;
wchar_t *to_buf;
wchar_t scratchbuf[BUFSIZ];
Status tmp_state;
if (!state)
state = &tmp_state;
if (!conv || !from || !from_len) {
*state = XLookupNone;
return 0;
}
/* Reset the converter. The CompoundText at 'from' starts in
initial state. */
_XlcResetConverter(conv);
from_left = from_len;
to_left = BUFSIZ;
from_cnvlen = 0;
to_cnvlen = 0;
for (;;) {
from_buf = &from[from_cnvlen];
from_savelen = from_left;
to_buf = &scratchbuf[to_cnvlen];
to_savelen = to_left;
if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
(XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
*state = XLookupNone;
return 0;
}
from_cnvlen += (from_savelen - from_left);
to_cnvlen += (to_savelen - to_left);
if (from_left == 0) {
if (!to_cnvlen){
*state = XLookupNone;
return 0;
}
break;
}
}
if (!to || !to_len || (to_len < to_cnvlen)) {
*state = XBufferOverflow;
} else {
memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
*state = XLookupChars;
}
return to_cnvlen;
}
Public int
_Ximctstoutf8(
XIM xim,
char *from,
int from_len,
char *to,
int to_len,
Status *state)
{
return _Ximctsconvert(((Xim)xim)->private.proto.ctoutf8_conv,
from, from_len, to, to_len, state);
}
Public int
_XimProtoMbLookupString(
XIC xic,
XKeyEvent *ev,
char *buffer,
int bytes,
KeySym *keysym,
Status *state)
{
Xic ic = (Xic)xic;
Xim im = (Xim)ic->core.im;
int ret;
Status tmp_state;
XimCommitInfo info;
if (!IS_SERVER_CONNECTED(im))
return 0;
if (!state)
state = &tmp_state;
if ((ev->type == KeyPress) && (ev->keycode == 0)) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) {
*state = XLookupNone;
return 0;
}
ret = im->methods->ctstombs((XIM)im, info->string,
info->string_len, buffer, bytes, state);
if (*state == XBufferOverflow)
return ret;
if (keysym && (info->keysym && *(info->keysym))) {
*keysym = *(info->keysym);
if (*state == XLookupChars)
*state = XLookupBoth;
else
*state = XLookupKeySym;
}
_XimUnregCommitInfo(ic);
} else if (ev->type == KeyPress) {
ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
if (ret > 0) {
if (ret > bytes)
*state = XBufferOverflow;
else if (keysym && *keysym != NoSymbol)
*state = XLookupBoth;
else
*state = XLookupChars;
} else {
if (keysym && *keysym != NoSymbol)
*state = XLookupKeySym;
else
*state = XLookupNone;
}
} else {
*state = XLookupNone;
ret = 0;
}
return ret;
}
Public int
_XimProtoWcLookupString(
XIC xic,
XKeyEvent *ev,
wchar_t *buffer,
int bytes,
KeySym *keysym,
Status *state)
{
Xic ic = (Xic)xic;
Xim im = (Xim)ic->core.im;
int ret;
Status tmp_state;
XimCommitInfo info;
if (!IS_SERVER_CONNECTED(im))
return 0;
if (!state)
state = &tmp_state;
if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) {
*state = XLookupNone;
return 0;
}
ret = im->methods->ctstowcs((XIM)im, info->string,
info->string_len, buffer, bytes, state);
if (*state == XBufferOverflow)
return ret;
if (keysym && (info->keysym && *(info->keysym))) {
*keysym = *(info->keysym);
if (*state == XLookupChars)
*state = XLookupBoth;
else
*state = XLookupKeySym;
}
_XimUnregCommitInfo(ic);
} else if (ev->type == KeyPress) {
ret = _XimLookupWCText(ic, ev, buffer, bytes, keysym, NULL);
if (ret > 0) {
if (ret > bytes)
*state = XBufferOverflow;
else if (keysym && *keysym != NoSymbol)
*state = XLookupBoth;
else
*state = XLookupChars;
} else {
if (keysym && *keysym != NoSymbol)
*state = XLookupKeySym;
else
*state = XLookupNone;
}
} else {
*state = XLookupNone;
ret = 0;
}
return ret;
}
Public int
_XimProtoUtf8LookupString(
XIC xic,
XKeyEvent *ev,
char *buffer,
int bytes,
KeySym *keysym,
Status *state)
{
Xic ic = (Xic)xic;
Xim im = (Xim)ic->core.im;
int ret;
Status tmp_state;
XimCommitInfo info;
if (!IS_SERVER_CONNECTED(im))
return 0;
if (!state)
state = &tmp_state;
if (ev->type == KeyPress && ev->keycode == 0) { /* Filter function */
if (!(info = ic->private.proto.commit_info)) {
*state = XLookupNone;
return 0;
}
ret = im->methods->ctstoutf8((XIM)im, info->string,
info->string_len, buffer, bytes, state);
if (*state == XBufferOverflow)
return ret;
if (keysym && (info->keysym && *(info->keysym))) {
*keysym = *(info->keysym);
if (*state == XLookupChars)
*state = XLookupBoth;
else
*state = XLookupKeySym;
}
_XimUnregCommitInfo(ic);
} else if (ev->type == KeyPress) {
ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
if (ret > 0) {
if (ret > bytes)
*state = XBufferOverflow;
else if (keysym && *keysym != NoSymbol)
*state = XLookupBoth;
else
*state = XLookupChars;
} else {
if (keysym && *keysym != NoSymbol)
*state = XLookupKeySym;
else
*state = XLookupNone;
}
} else {
*state = XLookupNone;
ret = 0;
}
return ret;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.