file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/989216.c |
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
bool isMatch(char * s, char * p){
int sLength = (int)strlen(s), pLength = (int)strlen(p);
if (pLength == 0) {
return sLength == 0;
}
//先比较第一位的情况
bool firstMatch = sLength > 0 && (p[0] == s[0] || p[0] == '.');
//* 会出现第二个位置,出现后连带前一个字符,和对应的s位置比较,
//如果第一位相等 s+1 继续比较
//如果第一位不相等忽略 p+2 继续比较
if (pLength >= 2 && p[1] == '*') {
return isMatch(s , p + 2) || (firstMatch && isMatch(s + 1, p));
} else {
return firstMatch && isMatch(s + 1, p + 1);
}
}
int main(int argc, const char * argv[]) {
// char *s = "mississippi";
// char *p = "mis*is*p*.";
// printf("%d\n", isMatch(s, p));
// char *s = "aaa";
// char *p = "aaaa";
// printf("%d\n", isMatch(s, p)); //0
// char *s = "aa";
// char *p = ".aa";
// printf("%d\n", isMatch(s, p)); //0
char *s = "aaa";
char *p = "ab*a*c*a";
printf("%d\n", isMatch(s, p)); //1
//aaa aaaa 0
//aaa ab*a*c*a 1
return 0;
}
|
the_stack_data/54825056.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: esuguimo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/12 11:42:49 by esuguimo #+# #+# */
/* Updated: 2019/10/14 15:09:11 by esuguimo ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_ft(int *nbr)
{
*nbr = 42;
}
|
the_stack_data/193892302.c | #include <grp.h>
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char **argv) {
int n,i;
if (argc < 2) {
printf("Usage: %s <user>\n", argv[0]);
return 0;
}
// initialize the group access list and using groups of which user is a memeber.
if (initgroups(argv[1], 1234) < 0) {
perror("initgroups");
return 1;
}
gid_t grouplist[16];
n = getgroups(16, grouplist);
for (i = 0; i < n; i++) {
printf("(%d) group ID: %d\n", i, grouplist[i]);
}
return 0;
}
|
the_stack_data/92718.c |
//{{BLOCK(VUEngineLogo)
//======================================================================
//
// VUEngineLogo, 96x16@2,
// + 24 tiles (t|f reduced) not compressed
// + regular map (flat), not compressed, 12x2
// Total size: 400 + 48 = 448
//
// Exported by Cearn's GBA Image Transmogrifier, v0.8.6
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================
const unsigned int VUEngineLogoTiles[100] __attribute__((aligned(4)))=
{
0x03F80000,0x0FF803F8,0x3FE00FF8,0xFF803FE0,
0xFE000000,0xFF80FE00,0x3FE0FF80,0x0FF83FE0,0x83FE0000,0x83FE83FE,0x83FE83FE,0x83FE83FE,
0xFEFF0000,0xFEFFFEFF,0xFEFFFEFF,0xFEFFFEFF,0x8FFF0000,0x8FFF8FFF,0x80038003,0x83FF8003,
0xFFFF0000,0xF6AFF6AF,0xDAAFDAAF,0x6AAF6AAF,0xFFFF0000,0xFDABFDAB,0xADABBDAB,0xADABADAB,
0xFFFF0000,0x6AAADAAB,0xABDAAAAA,0xFFF6AFF6,0xFFFF0000,0xDABFDABF,0xDAB6DABD,0xDABFDAB6,
0xFFFF0000,0xBF6ABF6A,0xBDAABDAA,0xB6AAB6AA,0xFFFF0000,0xAADAAADA,0x6ADAAADA,0xAADA6ADA,
0x0FFF0000,0x0F6A0F6A,0x0FFF0F6A,0x0FDA0FFF,0xFE00FF80,0xF800FE00,0xE000F800,0x8000E000,
0x03FF0FF8,0x00FF03FF,0x003F00FF,0x000F003F,0x83FE83FE,0x83FE83FE,0x83FE83FE,0xFFE0FFF8,
0xFEFFFEFF,0xFEFFFEFF,0xFEFFFEFF,0xFE0FFE3F,0x83FF83FF,0x80038003,0x8FFF8003,0x8FFF8FFF,
0xAAAFAAAF,0xB6AFB6AF,0xF6AFF6AF,0xFFFFF6AF,0xADAAADAA,0xADAAADAA,0xFDAABDAA,0xFFFFFDAB,
0xABF6ABF6,0xAFDAABF6,0x6AAAAAAA,0xFFFFDAAB,0xDAB6DAB6,0xDAB6DAB6,0xDABFDABD,0xFFFFDABF,
0xAAAAAAAA,0xAB6AAB6A,0xAF6AAF6A,0xFFFFBF6A,0xAADAAADA,0x6ADA6ADA,0xAADAAADA,0xFFFFAADA,
0x0FDA0FDA,0x0FFF0FFF,0x0F6A0F6A,0x0FFF0F6A,
};
const unsigned short VUEngineLogoMap[24] __attribute__((aligned(4)))=
{
0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,
0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f,
0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,
};
//}}BLOCK(VUEngineLogo) |
the_stack_data/413678.c | /*
* Extracted from https://github.com/sosy-lab/sv-benchmarks.
* Contributed by Vladimír Štill (https://divine.fi.muni.cz).
* Description: A test case for pthread TLS. This test demonstartes that
* destructors are called.
*/
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
void destructor(void *v)
{
long val = (long)v;
assert(val != 42);
}
void *worker(void *k)
{
pthread_key_t *key = k;
int r = pthread_setspecific(*key, (void *)42);
assert(r == 0);
return 0;
}
int main()
{
pthread_key_t key;
int r = pthread_key_create(&key, &destructor);
if(r == ENOMEM)
{
exit(1);
}
assert(r == 0 || r == EAGAIN);
pthread_t tid;
pthread_create(&tid, NULL, worker, &key);
r = pthread_setspecific(key, (void *)16);
if(r == ENOMEM)
{
exit(1);
}
assert(r == 0 || r == EAGAIN);
pthread_join(tid, NULL);
return 0;
}
|
the_stack_data/940388.c | #include<stdio.h>
int z(long long x){
int i=2;
while(x%i!=0){
i++;
}
if(i<x) return 0; // bushi zhishu
else return 1; // shi zhishu
}
int z(long long);
int main(){
long long n;
scanf("%lld",&n);
long long m=n+1;
while(z(m)==0){
m++;
}
printf("%lld",m);
return 0;
} |
the_stack_data/54690.c | #include <stdio.h>
int main (int arg, char* argv[])
{
int num1;
printf("\nIngrese un n%cmero entero: ", 163);
scanf("%d", &num1);
if (num1>10)
printf("El n%cmero %d es mayor a 10\n", 163, num1 );
if (num1<10)
printf("EL n%cmero %d es menor a 10\n", 163, num1 );
getchar();
return 0;
}
|
the_stack_data/12637228.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* aff_first_param.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kibotrel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/26 11:27:48 by kibotrel #+# #+# */
/* Updated: 2019/02/26 11:27:49 by kibotrel ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int ac, char **av)
{
if (ac > 1)
while (*av[1])
write(1, &*av[1]++, 1);
return (0 * write(1, "\n", 1));
}
|
the_stack_data/55518.c | #include <stdio.h>
// Let’s look at specifying PI as an alias for its value
#define PI 3.14159f
int main(void) {
float radius = 0.0f;
float diameter = 0.0f;
float circumference = 0.0f;
float area = 0.0f;
printf("Input the diameter of a table:");
scanf("%f", &diameter);
radius = diameter/2.0f;
circumference = 2.0f * PI * radius;
area = PI * radius * radius;
printf("\nThe circunference is %.2f", circumference);
printf("\nThe area is %.2f", area);
return 0;
} |
the_stack_data/134963.c | // RUN: %clam -O0 --inline --lower-unsigned-icmp --crab-dom=int --crab-check=assert --crab-sanity-checks "%s" 2>&1 | OutputCheck -l debug %s
// CHECK: ^0 Number of total safe checks$
// CHECK: ^0 Number of total error checks$
// CHECK: ^1 Number of total warning checks$
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) {
if (!(cond)) {
ERROR: __VERIFIER_error();
}
return;
}
/**
The fact x is unsigned makes this program hard to verify because it
requires non-trivial boolean reasoning due to the lowering of
unsigned < operator and >= to signed operators.
**/
int main(void) {
unsigned int x = 0;
while (x < 0x0fffffff) {
x++;
}
__VERIFIER_assert(x > 0x0fffffff);
}
|
the_stack_data/93490.c | const unsigned char gImage_rain[356] = { 0X00,0X01,0X32,0X00,0X32,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF0,0X0F,0X80,
0X00,0X00,0X00,0X0F,0XFC,0X7F,0XF0,0X00,0X00,0X00,0X3F,0XFF,0XFF,0XF8,0X00,0X00,
0X00,0X7F,0XFF,0XFF,0XFC,0X00,0X00,0X00,0XFF,0XFF,0XFF,0XFE,0X00,0X00,0X00,0XFF,
0XFF,0XFF,0XFF,0X00,0X00,0X01,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X01,0XFF,0XFF,0XFF,
0XFF,0X80,0X00,0X03,0XFF,0XFF,0XFF,0XFF,0X80,0X00,0X3F,0XFF,0XFF,0XFF,0XFF,0X80,
0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0X80,0X01,0XFF,0XFF,0XFF,0XFF,0XFF,0X80,0X03,0XFF,
0XFF,0XFF,0XFF,0XFF,0X80,0X07,0XFF,0XFF,0XFF,0XFF,0XFF,0X80,0X3F,0XFF,0XFF,0XFF,
0XFF,0XFF,0X80,0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,0X80,0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,
0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XFE,0X00,0X7F,
0XFF,0XFF,0XFF,0XFF,0XFC,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XF8,0X00,0X3F,0XFF,0XFF,
0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X40,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0X30,0X18,0X00,0X00,
0X00,0X08,0XC0,0X30,0X10,0X00,0X00,0X00,0X19,0X84,0X63,0X30,0X00,0X00,0X00,0X30,
0X0C,0X42,0X20,0X00,0X00,0X00,0X30,0X18,0X06,0X00,0X00,0X00,0X00,0X00,0X18,0X04,
0X08,0X00,0X00,0X00,0X00,0X00,0X00,0X18,0X00,0X00,0X00,0X03,0X00,0X40,0X30,0X00,
0X00,0X00,0X46,0X00,0XC0,0X30,0X00,0X00,0X00,0XC6,0X10,0XC3,0X00,0X00,0X00,0X00,
0X80,0X30,0X82,0X00,0X00,0X00,0X00,0X80,0X20,0X06,0X00,0X00,0X00,0X00,0X00,0X20,
0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,};
|
the_stack_data/176705166.c | /**
* File: money.c
*
* Author:
* ID:
* Date:
*/
int main(){
return 0;
} |
the_stack_data/745513.c | # define DBG_ERROR(dbg_logger, format, args...) if (1){\
char dbg_buffer[256]; \
__builtin_snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
__FILE__":%5d: " format , __LINE__ , ## args); \
};
void testPasswordStore1(int argc, char **argv) {
const char *pw1="Secret1";
char pw[256];
DBG_ERROR(0, "Bad password, expected [%s], got [%s].", pw1, pw);
}
|
the_stack_data/1012507.c | /*
Example of a C program that reads a binary PPM image file and writes it out as a new PPM file.
Author: Dr Anton Gerdelan.
Licence: see LICENSE.txt in repository root.
Repository: https://github.com/capnramses/pro_programming_tools_c_cpp
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define FILE_IN "in.ppm"
#define FILE_OUT "out.ppm"
struct image_t {
uint8_t* ptr;
int width, height, n_channels;
};
struct image_t ppm_read( const char* filename ) {
struct image_t image;
memset( &image, 0, sizeof( struct image_t ) );
image.n_channels = 3; // 3 for RGB
FILE* fptr = fopen( filename, "rb" ); // ‘rb’ is ‘read binary’
if ( !fptr ) { return image; }
{
// read header
char type[2];
int max_val;
int n = fscanf( fptr, "%c%c %i %i %i\n", &type[0], &type[1], &image.width, &image.height, &max_val );
if ( 5 != n || type[0] != 'P' || type[1] != '6' ) {
fclose( fptr );
return image;
}
// read body
size_t pixel_data_sz = image.width * image.height * image.n_channels;
image.ptr = malloc( pixel_data_sz );
if ( !image.ptr ) {
fclose( fptr );
return image;
}
n = fread( image.ptr, pixel_data_sz, 1, fptr );
if ( 1 != n ) {
fclose( fptr );
free( image.ptr );
memset( &image, 0, sizeof( struct image_t ) );
return image;
}
}
fclose( fptr );
return image;
}
bool ppm_write( const char* filename, struct image_t image ) {
FILE* fptr = fopen( filename, "wb" );
if ( !fptr ) { return false; }
{
fprintf( fptr, "P6\n%i %i\n255\n", image.width, image.height );
size_t sz = image.width * image.height * image.n_channels;
int n = fwrite( image.ptr, sz, 1, fptr );
if ( 1 != n ) {
fclose( fptr );
return false;
}
}
fclose( fptr );
return true;
}
int main() {
struct image_t image = ppm_read( FILE_IN );
if ( !image.ptr ) {
fprintf( stderr, "ERROR:reading image from `%s`\n", FILE_IN );
return 1;
}
printf( "parsed PPM from `%s`\n", FILE_IN );
// write again to test reading worked
bool ret = ppm_write( FILE_OUT, image );
if ( !ret ) {
fprintf( stderr, "ERROR:writing image to `%s`\n", FILE_OUT );
return 1;
}
printf( "wrote PPM file to `%s`\n", FILE_OUT );
return 0;
}
|
the_stack_data/11075659.c | #define _GNU_SOURCE
#include <stddef.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
extern int __optpos, __optreset;
static void permute(char *const *argv, int dest, int src)
{
char **av = (char **)argv;
char *tmp = av[src];
int i;
for (i=src; i>dest; i--)
av[i] = av[i-1];
av[dest] = tmp;
}
void __getopt_msg(const char *, const char *, const char *, size_t);
static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
{
int ret, skipped, resumed;
if (!optind || __optreset) {
__optreset = 0;
__optpos = 0;
optind = 1;
}
if (optind >= argc || !argv[optind]) return -1;
skipped = optind;
if (optstring[0] != '+' && optstring[0] != '-') {
int i;
for (i=optind; ; i++) {
if (i >= argc || !argv[i]) return -1;
if (argv[i][0] == '-' && argv[i][1]) break;
}
optind = i;
}
resumed = optind;
ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
if (resumed > skipped) {
int i, cnt = optind-resumed;
for (i=0; i<cnt; i++)
permute(argv, skipped, optind-1);
optind = skipped + cnt;
}
return ret;
}
static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
{
optarg = 0;
if (longopts && argv[optind][0] == '-' &&
((longonly && argv[optind][1] && argv[optind][1] != '-') ||
(argv[optind][1] == '-' && argv[optind][2])))
{
int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
int i, cnt, match;
char *opt;
for (cnt=i=0; longopts[i].name; i++) {
const char *name = longopts[i].name;
opt = argv[optind]+1;
if (*opt == '-') opt++;
for (; *name && *name == *opt; name++, opt++);
if (*opt && *opt != '=') continue;
match = i;
if (!*name) {
cnt = 1;
break;
}
cnt++;
}
if (cnt==1) {
i = match;
optind++;
optopt = longopts[i].val;
if (*opt == '=') {
if (!longopts[i].has_arg) {
if (colon || !opterr)
return '?';
__getopt_msg(argv[0],
": option does not take an argument: ",
longopts[i].name,
strlen(longopts[i].name));
return '?';
}
optarg = opt+1;
} else if (longopts[i].has_arg == required_argument) {
if (!(optarg = argv[optind])) {
if (colon) return ':';
if (!opterr) return '?';
__getopt_msg(argv[0],
": option requires an argument: ",
longopts[i].name,
strlen(longopts[i].name));
return '?';
}
optind++;
}
if (idx) *idx = i;
if (longopts[i].flag) {
*longopts[i].flag = longopts[i].val;
return 0;
}
return longopts[i].val;
}
if (argv[optind][1] == '-') {
if (!colon && opterr)
__getopt_msg(argv[0], cnt ?
": option is ambiguous: " :
": unrecognized option: ",
argv[optind]+2,
strlen(argv[optind]+2));
optind++;
return '?';
}
}
return getopt(argc, argv, optstring);
}
int getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
{
return __getopt_long(argc, argv, optstring, longopts, idx, 0);
}
int getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
{
return __getopt_long(argc, argv, optstring, longopts, idx, 1);
}
|
the_stack_data/22011714.c | /*
* Copyright (c) 2011 Parallax, Inc.
* Written by Eric R. Smith, Total Spectrum Software Inc.
* MIT licensed (see terms at end of file)
*/
#include <stdio.h>
#include <stdarg.h>
int fprintf(FILE *fp, const char *fmt, ...)
{
va_list args;
int r;
va_start(args, fmt);
r = vfprintf(fp, fmt, args);
va_end(args);
return r;
}
/* +--------------------------------------------------------------------
* ¦ TERMS OF USE: MIT License
* +--------------------------------------------------------------------
* 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.
* +--------------------------------------------------------------------
*/
|
the_stack_data/15762336.c | #include <stdio.h>
#include "sha256.h"
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("Invalid usage.\nUsage: ./sha256 {relative path to file}\n");
return 1;
}
sha256(argv[1]);
return 0;
}
|
the_stack_data/234518523.c |
void set(int *a)
{
*a = 8;
}
/* globals are initialized by
* ConstantExpr, so this is different
* test thatn funcptr1.c */
void (*s)(int *) = set;
int main(void)
{
int a, b = 0xfe, c = 0xef;
a = b + c;
b = 3;
c = 5;
s(&a);
test_assert(a == 8);
return 0;
}
|
the_stack_data/20345.c | #include<stdio.h>
main(){
int x,i;
scanf("%d",&x);
for (i=0; i<=100; i++){
if (i%x==0){
printf("\n%i eh divisivel por %i",i,x);
}
}
getch();
}
|
the_stack_data/167329998.c | #include <stdio.h>
int main()
{
int n1,n2;
scanf("%d %d",&n1,&n2);
printf("%d\n",(n1+n2));
return 0;
}
|
the_stack_data/708544.c | /* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to [email protected]
before changing it!
Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001
Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Ditto for AIX 3.2 and <stdlib.h>. */
#ifndef _NO_PROTO
#define _NO_PROTO
#endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if !defined __STDC__ || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#define GETOPT_INTERFACE_VERSION 2
#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
#include <gnu-versions.h>
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
#define ELIDE_CODE
#endif
#endif
#ifndef ELIDE_CODE
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
#include <unistd.h>
#endif /* GNU C library. */
#ifdef VMS
#include <unixlib.h>
#if HAVE_STRING_H - 0
#include <string.h>
#endif
#endif
#ifndef _
/* This is for other GNU distributions with internationalized messages. */
#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
#include <libintl.h>
#ifndef _
#define _(msgid) gettext(msgid)
#endif
#else
#define _(msgid) (msgid)
#endif
#if defined _LIBC && defined USE_IN_LIBIO
#include <wchar.h>
#endif
#endif
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
to intersperse the options with the other arguments.
As `getopt' works, it permutes the elements of ARGV so that,
when it is done, all the options precede everything else. Thus
all application programs are extended to handle flexible argument order.
Setting the environment variable POSIXLY_CORRECT disables permutation.
Then the behavior is completely standard.
GNU application programs can use a third alternative mode in which
they can distinguish the relative order of options and other arguments. */
#include "getopt.h"
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
/* 1003.2 says this must be 1 before any call. */
int optind = 1;
/* Formerly, initialization of getopt depended on optind==0, which
causes problems with re-calling getopt as programs generally don't
know that. */
int __getopt_initialized;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
This allows us to pick up the scan where we left off.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
static char *nextchar;
/* Callers store zero here to inhibit the error message
for unrecognized options. */
int opterr = 1;
/* Set to an option character which was unrecognized.
This must be initialized on some systems to avoid linking in the
system's own getopt implementation. */
int optopt = '?';
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters.
PERMUTE is the default. We permute the contents of ARGV as we scan,
so that eventually all the non-options are at the end. This allows options
to be given in any order, even with programs that were not written to
expect this.
RETURN_IN_ORDER is an option available to programs that were written
to expect options and other ARGV-elements in any order and that care about
the ordering of the two. We describe each non-option ARGV-element
as if it were the argument of an option with character code 1.
Using `-' as the first character of the list of option characters
selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
static enum { REQUIRE_ORDER,
PERMUTE,
RETURN_IN_ORDER
} ordering;
/* Value of POSIXLY_CORRECT environment variable. */
static char *posixly_correct;
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
because there are many ways it can cause trouble.
On some systems, it contains special magic macros that don't work
in GCC. */
#include <string.h>
#define my_index strchr
#else
#define HAVE_STRING_H 1
#if HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
/* Avoid depending on library functions or files
whose names are inconsistent. */
#ifndef getenv
extern char *getenv();
#endif
static char *
my_index(str, chr)
const char *str;
int chr;
{
while (*str)
{
if (*str == chr)
return (char *)str;
str++;
}
return 0;
}
/* If using GCC, we can safely declare strlen this way.
If not using GCC, it is ok not to declare it. */
#ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
That was relevant to code that was here before. */
#if (!defined __STDC__ || !__STDC__) && !defined strlen
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen(const char *);
#endif /* not __STDC__ */
#endif /* __GNUC__ */
#endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first of them;
`last_nonopt' is the index after the last of them. */
static int first_nonopt;
static int last_nonopt;
#ifdef _LIBC
/* Stored original parameters.
XXX This is no good solution. We should rather copy the args so
that we can compare them later. But we must not use malloc(3). */
extern int __libc_argc;
extern char **__libc_argv;
/* Bash 2.0 gives us an environment variable containing flags
indicating ARGV elements that should not be considered arguments. */
#ifdef USE_NONOPTION_FLAGS
/* Defined in getopt_init.c */
extern char *__getopt_nonoption_flags;
static int nonoption_flags_max_len;
static int nonoption_flags_len;
#endif
#ifdef USE_NONOPTION_FLAGS
#define SWAP_FLAGS(ch1, ch2) \
if (nonoption_flags_len > 0) \
{ \
char __tmp = __getopt_nonoption_flags[ch1]; \
__getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
__getopt_nonoption_flags[ch2] = __tmp; \
}
#else
#define SWAP_FLAGS(ch1, ch2)
#endif
#else /* !_LIBC */
#define SWAP_FLAGS(ch1, ch2)
#endif /* _LIBC */
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
The other is elements [last_nonopt,optind), which contains all
the options processed since those non-options were skipped.
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
#if defined __STDC__ && __STDC__
static void exchange(char **);
#endif
static void
exchange(argv) char **argv;
{
int bottom = first_nonopt;
int middle = last_nonopt;
int top = optind;
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
That puts the shorter segment into the right place.
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
#if defined _LIBC && defined USE_NONOPTION_FLAGS
/* First make sure the handling of the `__getopt_nonoption_flags'
string can work normally. Our top argument must be in the range
of the string. */
if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
{
/* We must extend the array. The user plays games with us and
presents new arguments. */
char *new_str = malloc(top + 1);
if (new_str == NULL)
nonoption_flags_len = nonoption_flags_max_len = 0;
else
{
memset(__mempcpy(new_str, __getopt_nonoption_flags,
nonoption_flags_max_len),
'\0', top + 1 - nonoption_flags_max_len);
nonoption_flags_max_len = top + 1;
__getopt_nonoption_flags = new_str;
}
}
#endif
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
SWAP_FLAGS(bottom + i, top - (middle - bottom) + i);
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
}
else
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
SWAP_FLAGS(bottom + i, middle + i);
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
/* Update records for the slots the non-options now occupy. */
first_nonopt += (optind - last_nonopt);
last_nonopt = optind;
}
/* Initialize the internal data when the first call is made. */
#if defined __STDC__ && __STDC__
static const char *_getopt_initialize(int, char *const *, const char *);
#endif
static const char *
_getopt_initialize(argc, argv, optstring) int argc;
char *const *argv;
const char *optstring;
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
first_nonopt = last_nonopt = optind;
nextchar = NULL;
posixly_correct = getenv("POSIXLY_CORRECT");
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
{
ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == '+')
{
ordering = REQUIRE_ORDER;
++optstring;
}
else if (posixly_correct != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
#if defined _LIBC && defined USE_NONOPTION_FLAGS
if (posixly_correct == NULL && argc == __libc_argc && argv == __libc_argv)
{
if (nonoption_flags_max_len == 0)
{
if (__getopt_nonoption_flags == NULL || __getopt_nonoption_flags[0] == '\0')
nonoption_flags_max_len = -1;
else
{
const char *orig_str = __getopt_nonoption_flags;
int len = nonoption_flags_max_len = strlen(orig_str);
if (nonoption_flags_max_len < argc)
nonoption_flags_max_len = argc;
__getopt_nonoption_flags =
(char *)malloc(nonoption_flags_max_len);
if (__getopt_nonoption_flags == NULL)
nonoption_flags_max_len = -1;
else
memset(__mempcpy(__getopt_nonoption_flags, orig_str, len),
'\0', nonoption_flags_max_len - len);
}
}
nonoption_flags_len = nonoption_flags_max_len;
}
else
nonoption_flags_len = 0;
#endif
return optstring;
}
/* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING.
If an element of ARGV starts with '-', and is not exactly "-" or "--",
then it is an option element. The characters of this element
(aside from the initial '-') are option characters. If `getopt'
is called repeatedly, it returns successively each of the option characters
from each of the option elements.
If `getopt' finds another option character, it returns that character,
updating `optind' and `nextchar' so that the next call to `getopt' can
resume the scan with the following option character or ARGV-element.
If there are no more option characters, `getopt' returns -1.
Then `optind' is the index in ARGV of the first ARGV-element
that is not an option. (The ARGV-elements have been permuted
so that those that are not options now come last.)
OPTSTRING is a string containing the legitimate option characters.
If an option character is seen that is not listed in OPTSTRING,
return '?' after printing an error message. If you set `opterr' to
zero, the error message is suppressed but we still return '?'.
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
so the following text in the same ARGV-element, or the text of the following
ARGV-element, is returned in `optarg'. Two colons mean an option that
wants an optional arg; if there is text in the current ARGV-element,
it is returned in `optarg', otherwise `optarg' is set to zero.
If OPTSTRING starts with `-' or `+', it requests different methods of
handling the non-option ARGV-elements.
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
Long-named options begin with `--' instead of `-'.
Their names may be abbreviated as long as the abbreviation is unique
or is an exact match for some defined option. If they have an
argument, it follows the option name in the same ARGV-element, separated
from the option name by a `=', or else the in next ARGV-element.
When `getopt' finds a long-named option, it returns 0 if that option's
`flag' field is nonzero, the value of the option's `val' field
if the `flag' field is zero.
The elements of ARGV aren't really const, because we permute them.
But we pretend they're const in the prototype to be compatible
with other systems.
LONGOPTS is a vector of `struct option' terminated by an
element containing a name which is zero.
LONGIND returns the index in LONGOPT of the long-named option found.
It is only valid when a long-named option has been found by the most
recent call.
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
long-named options. */
int
_getopt_internal(argc, argv, optstring, longopts, longind, long_only) int argc;
char *const *argv;
const char *optstring;
const struct option *longopts;
int *longind;
int long_only;
{
int print_errors = opterr;
if (optstring[0] == ':')
print_errors = 0;
if (argc < 1)
return -1;
optarg = NULL;
if (optind == 0 || !__getopt_initialized)
{
if (optind == 0)
optind = 1; /* Don't scan ARGV[0], the program name. */
optstring = _getopt_initialize(argc, argv, optstring);
__getopt_initialized = 1;
}
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
from the shell indicating it is not an option. The later information
is only used when the used in the GNU libc. */
#if defined _LIBC && defined USE_NONOPTION_FLAGS
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' || (optind < nonoption_flags_len && __getopt_nonoption_flags[optind] == '1'))
#else
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
#endif
if (nextchar == NULL || *nextchar == '\0')
{
/* Advance to the next ARGV-element. */
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
moved back by the user (who may also have changed the arguments). */
if (last_nonopt > optind)
last_nonopt = optind;
if (first_nonopt > optind)
first_nonopt = optind;
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange((char **)argv);
else if (last_nonopt != optind)
first_nonopt = optind;
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
while (optind < argc && NONOPTION_P)
optind++;
last_nonopt = optind;
}
/* The special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (optind != argc && !strcmp(argv[optind], "--"))
{
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange((char **)argv);
else if (first_nonopt == last_nonopt)
first_nonopt = optind;
last_nonopt = argc;
optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
if (optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
return -1;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
if (NONOPTION_P)
{
if (ordering == REQUIRE_ORDER)
return -1;
optarg = argv[optind++];
return 1;
}
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-'));
}
/* Decode the current option-ARGV-element. */
/* Check whether the ARGV-element is a long option.
If long_only and the ARGV-element has the form "-f", where f is
a valid short option, don't consider it an abbreviated form of
a long option that starts with f. Otherwise there would be no
way to give the -f short option.
On the other hand, if there's a long option "fubar" and
the ARGV-element is "-fu", do consider that an abbreviation of
the long option, just like "--fu", and not "-f" with arg "u".
This distinction seems to be the most useful approach. */
if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !my_index(optstring, argv[optind][1])))))
{
char *nameend;
const struct option *p;
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound = -1;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
/* Do nothing. */;
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp(p->name, nextchar, nameend - nextchar))
{
if ((unsigned int)(nameend - nextchar) == (unsigned int)strlen(p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf, _("%s: option `%s' is ambiguous\n"),
argv[0], argv[optind]);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr, _("%s: option `%s' is ambiguous\n"),
argv[0], argv[optind]);
#endif
}
nextchar += strlen(nextchar);
optind++;
optopt = 0;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
optind++;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = nameend + 1;
else
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
#endif
if (argv[optind - 1][1] == '-')
{
/* --option */
#if defined _LIBC && defined USE_IN_LIBIO
__asprintf(&buf, _("\
%s: option `--%s' doesn't allow an argument\n"),
argv[0], pfound->name);
#else
fprintf(stderr, _("\
%s: option `--%s' doesn't allow an argument\n"),
argv[0], pfound->name);
#endif
}
else
{
/* +option or -option */
#if defined _LIBC && defined USE_IN_LIBIO
__asprintf(&buf, _("\
%s: option `%c%s' doesn't allow an argument\n"),
argv[0], argv[optind - 1][0],
pfound->name);
#else
fprintf(stderr, _("\
%s: option `%c%s' doesn't allow an argument\n"),
argv[0], argv[optind - 1][0], pfound->name);
#endif
}
#if defined _LIBC && defined USE_IN_LIBIO
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#endif
}
nextchar += strlen(nextchar);
optopt = pfound->val;
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (optind < argc)
optarg = argv[optind++];
else
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf,
_("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr,
_("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
#endif
}
nextchar += strlen(nextchar);
optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen(nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-' || my_index(optstring, *nextchar) == NULL)
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
#endif
if (argv[optind][1] == '-')
{
/* --option */
#if defined _LIBC && defined USE_IN_LIBIO
__asprintf(&buf, _("%s: unrecognized option `--%s'\n"),
argv[0], nextchar);
#else
fprintf(stderr, _("%s: unrecognized option `--%s'\n"),
argv[0], nextchar);
#endif
}
else
{
/* +option or -option */
#if defined _LIBC && defined USE_IN_LIBIO
__asprintf(&buf, _("%s: unrecognized option `%c%s'\n"),
argv[0], argv[optind][0], nextchar);
#else
fprintf(stderr, _("%s: unrecognized option `%c%s'\n"),
argv[0], argv[optind][0], nextchar);
#endif
}
#if defined _LIBC && defined USE_IN_LIBIO
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#endif
}
nextchar = (char *)"";
optind++;
optopt = 0;
return '?';
}
}
/* Look at and handle the next short option-character. */
{
char c = *nextchar++;
char *temp = my_index(optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;
if (temp == NULL || c == ':')
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
#endif
if (posixly_correct)
{
/* 1003.2 specifies the format of this message. */
#if defined _LIBC && defined USE_IN_LIBIO
__asprintf(&buf, _("%s: illegal option -- %c\n"),
argv[0], c);
#else
fprintf(stderr, _("%s: illegal option -- %c\n"), argv[0], c);
#endif
}
else
{
#if defined _LIBC && defined USE_IN_LIBIO
__asprintf(&buf, _("%s: invalid option -- %c\n"),
argv[0], c);
#else
fprintf(stderr, _("%s: invalid option -- %c\n"), argv[0], c);
#endif
}
#if defined _LIBC && defined USE_IN_LIBIO
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#endif
}
optopt = c;
return '?';
}
/* Convenience. Treat POSIX -W foo same as long option --foo */
if (temp[0] == 'W' && temp[1] == ';')
{
char *nameend;
const struct option *p;
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound = 0;
int option_index;
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
}
else if (optind == argc)
{
if (print_errors)
{
/* 1003.2 specifies the format of this message. */
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf, _("%s: option requires an argument -- %c\n"),
argv[0], c);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr, _("%s: option requires an argument -- %c\n"),
argv[0], c);
#endif
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
return c;
}
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
/* optarg is now the argument, see if it's in the
table of longopts. */
for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
/* Do nothing. */;
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp(p->name, nextchar, nameend - nextchar))
{
if ((unsigned int)(nameend - nextchar) == strlen(p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf, _("%s: option `-W %s' is ambiguous\n"),
argv[0], argv[optind]);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr, _("%s: option `-W %s' is ambiguous\n"),
argv[0], argv[optind]);
#endif
}
nextchar += strlen(nextchar);
optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = nameend + 1;
else
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf, _("\
%s: option `-W %s' doesn't allow an argument\n"),
argv[0], pfound->name);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr, _("\
%s: option `-W %s' doesn't allow an argument\n"),
argv[0], pfound->name);
#endif
}
nextchar += strlen(nextchar);
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (optind < argc)
optarg = argv[optind++];
else
{
if (print_errors)
{
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf, _("\
%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr,
_("%s: option `%s' requires an argument\n"),
argv[0], argv[optind - 1]);
#endif
}
nextchar += strlen(nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen(nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
nextchar = NULL;
return 'W'; /* Let the application handle it. */
}
if (temp[1] == ':')
{
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
optarg = nextchar;
optind++;
}
else
optarg = NULL;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
}
else if (optind == argc)
{
if (print_errors)
{
/* 1003.2 specifies the format of this message. */
#if defined _LIBC && defined USE_IN_LIBIO
char *buf;
__asprintf(&buf,
_("%s: option requires an argument -- %c\n"),
argv[0], c);
if (_IO_fwide(stderr, 0) > 0)
__fwprintf(stderr, L"%s", buf);
else
fputs(buf, stderr);
free(buf);
#else
fprintf(stderr,
_("%s: option requires an argument -- %c\n"),
argv[0], c);
#endif
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
nextchar = NULL;
}
}
return c;
}
}
int
getopt(argc, argv, optstring) int argc;
char *const *argv;
const char *optstring;
{
return _getopt_internal(argc, argv, optstring,
(const struct option *)0,
(int *)0,
0);
}
int getopt_long(int argc, char *const *argv, const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal(argc, argv, options, long_options, opt_index, 0, 0);
}
int getopt_long_only(int argc, char *const *argv, const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal(argc, argv, options, long_options, opt_index, 1, 0);
}
#endif /* Not ELIDE_CODE. */
#ifdef TEST
/* Compile with -DTEST to make an executable for use in testing
the above definition of `getopt'. */
int
main(argc, argv) int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
c = getopt(argc, argv, "abc:d:0123456789");
if (c == -1)
break;
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf("option %c\n", c);
break;
case 'a':
printf("option a\n");
break;
case 'b':
printf("option b\n");
break;
case 'c':
printf("option c with value `%s'\n", optarg);
break;
case '?':
break;
default:
printf("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
printf("\n");
}
exit(0);
}
#endif /* TEST */
|
the_stack_data/151705302.c | /* origin: FreeBSD /usr/src/lib/msun/src/e_log.c */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/* log(x)
* Return the logarithm of x
*
* Method :
* 1. Argument Reduction: find k and f such that
* x = 2^k * (1+f),
* where sqrt(2)/2 < 1+f < sqrt(2) .
*
* 2. Approximation of log(1+f).
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
* = 2s + s*R
* We use a special Remez algorithm on [0,0.1716] to generate
* a polynomial of degree 14 to approximate R The maximum error
* of this polynomial approximation is bounded by 2**-58.45. In
* other words,
* 2 4 6 8 10 12 14
* R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
* (the values of Lg1 to Lg7 are listed in the program)
* and
* | 2 14 | -58.45
* | Lg1*s +...+Lg7*s - R(z) | <= 2
* | |
* Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
* In order to guarantee error in log below 1ulp, we compute log
* by
* log(1+f) = f - s*(f - R) (if f is not too large)
* log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
*
* 3. Finally, log(x) = k*ln2 + log(1+f).
* = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
* Here ln2 is split into two floating point number:
* ln2_hi + ln2_lo,
* where n*ln2_hi is always exact for |n| < 2000.
*
* Special cases:
* log(x) is NaN with signal if x < 0 (including -INF) ;
* log(+INF) is +INF; log(0) is -INF with signal;
* log(NaN) is that NaN with no signal.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
#include <math.h>
#include <stdint.h>
static const double
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
double log(double x)
{
union {double f; uint64_t i;} u = {x};
double_t hfsq,f,s,z,R,w,t1,t2,dk;
uint32_t hx;
int k;
hx = u.i>>32;
k = 0;
if (hx < 0x00100000 || hx>>31) {
if (u.i<<1 == 0)
return -1/(x*x); /* log(+-0)=-inf */
if (hx>>31)
return (x-x)/0.0; /* log(-#) = NaN */
/* subnormal number, scale x up */
k -= 54;
x *= 0x1p54;
u.f = x;
hx = u.i>>32;
} else if (hx >= 0x7ff00000) {
return x;
} else if (hx == 0x3ff00000 && u.i<<32 == 0)
return 0;
/* reduce x into [sqrt(2)/2, sqrt(2)] */
hx += 0x3ff00000 - 0x3fe6a09e;
k += (int)(hx>>20) - 0x3ff;
hx = (hx&0x000fffff) + 0x3fe6a09e;
u.i = (uint64_t)hx<<32 | (u.i&0xffffffff);
x = u.f;
f = x - 1.0;
hfsq = 0.5*f*f;
s = f/(2.0+f);
z = s*s;
w = z*z;
t1 = w*(Lg2+w*(Lg4+w*Lg6));
t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
R = t2 + t1;
dk = k;
return s*(hfsq+R) + dk*ln2_lo - hfsq + f + dk*ln2_hi;
}
|
the_stack_data/7950430.c | #include<stdio.h>
int main()
{
int n,i,prime = 0;
scanf("%d",&n);
if(n==1)
{
prime = 1;
}
else
{
for (i=2;i<=n; i++)
{
if(n%i==0)
{
if(n==i) {prime = 1; break;}
else {prime =0; break;}
} else
{
prime =1;}
}
}
if (prime == 1) printf("Prime!");else printf("Not Prime!");
return 0;
}
|
the_stack_data/48907.c | #include<stdio.h>
int main(){
int n,a,b[16],i;
for(scanf("%d",&n);n;n--){
scanf("%d",&a);
for(i=0;a;i++){
b[i]=a%2;
a/=2;
}
for(;i;i--)
printf("%d",b[i-1]);
printf("\n");
}
return 0;
} |
the_stack_data/14200221.c | #include <stdio.h>
int puts(const char *str)
{
return printf("%s\n", str);
}
|
the_stack_data/396324.c | /* NAND FLASH控制器 */
#define NFCONF (*(volatile unsigned long *)0x4E000000)
#define NFCONT (*(volatile unsigned long *)0x4E000004)
#define NFCMMD (*(volatile unsigned long *)0x4E000008)
#define NFADDR (*(volatile unsigned long *)0x4E00000C)
#define NFDATA (*(volatile unsigned long *)0x4E000010)
#define NFSTAT (*(volatile unsigned long *)0x4E000020)
#define NF_CE_L() do{NFCONT &= ~(1 << 1);}while(0) /* 打开片选 */
#define NF_CE_H() do{NFCONT |= (1 << 1);}while(0) /* 关闭片选 */
#define NF_WAIT_RB() do{while(!(NFSTAT & (1 << 0)));}while(0) /* 等待NANDFLASH不忙 */
#define NF_DETECT_RB() do{while(!(NFSTAT & (1 << 2)));}while(0) /* 等待RnB信号变高,即不忙 */
extern void nand_read(unsigned int addr, unsigned char *buf, unsigned int len);
void clear_bss(void)
{
extern int __bss_start, __bss_end;
int *p = &__bss_start;
for ( ; p < &__bss_end; p++)
*p = 0;
}
void copy_code_to_sdram(unsigned char *addr, unsigned char *dest, unsigned int len)
{
nand_read((unsigned int)addr, dest, len);
}
void nand_cmd(unsigned char cmd)
{
volatile int i;
NFCMMD = cmd;
for (i = 0; i < 10; i++);
}
void nand_addr(unsigned int addr)
{
unsigned int col = addr % 2048;
unsigned int page = addr / 2048;
volatile int i;
NFADDR = col & 0xff;
for (i = 0; i < 10; i++);
NFADDR = (col >> 8) & 0x0ff;
for (i = 0; i < 10; i++);
NFADDR = page & 0xff;
for (i = 0; i < 10; i++);
NFADDR = (page >> 8) & 0xff;
for (i = 0; i < 10; i++);
NFADDR = (page >> 16) & 0xff;
for (i = 0; i < 10; i++);
}
void nand_read(unsigned int addr, unsigned char *buf, unsigned int len)
{
int i = 0;
int col = addr % 2048;
/* 1.选中,清除RnB信号 */
NF_CE_L();
while (i < len)
{
/* 2.发出读命令00h */
nand_cmd(0x00);
/* 3.发出地址(分5步发出) */
nand_addr(addr);
/* 4.发出读命令30h */
nand_cmd(0x30);
/* 5.判断状态 */
NF_WAIT_RB();
/* 6.读数据 */
for (; (col < 2048) && (i < len); col++)
{
buf[i] = *((unsigned char *)(&NFDATA));
addr++;
i++;
}
col = 0;
}
/* 7.取消选中 */
NF_CE_H();
}
void nand_init(void)
{
#define TACLS 0
#define TWRPH0 1
#define TWRPH1 0
/* 设置时序 */
NFCONF = (TACLS << 12) | (TWRPH0 << 8) | (TWRPH1 << 4);
/* 使能NAND Flash控制器,初始化ECC, 禁止片选 */
NFCONT = (1 << 4) | (1 << 1) | (1 << 0);
}
|
the_stack_data/40764149.c | // Fig. 9.2: fig09_02.c
// Using the integer conversion specifiers
#include <stdio.h>
int main(void)
{
printf("%d\n", 455);
printf("%i\n", 455); // i same as d in printf, different in scanf
printf("%d\n", +455); // plus sign does not print
printf("%d\n", -455); // minus sign prints
printf("%hd\n", 32000);
printf("%ld\n", 2000000000L); // L suffix makes literal a long
printf("%o\n", 455); // octal
printf("%u\n", 455);
printf("%u\n", -455);
printf("%x\n", 455); // hexadecimal with lowercase letters
printf("%X\n", 455); // hexadecimal with uppercase letters
}
/**************************************************************************
* (C) Copyright 1992-2015 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/ |
the_stack_data/136430.c | #include <math.h>
double plgndr(int l, int m, double x)
{
void nrerror(char error_text[]);
double fact,pll,pmm,pmmp1,somx2;
int i,ll;
if (m < 0 || m > l || fabs(x) > 1.0)
nrerror("Bad arguments in routine plgndr");
pmm=1.0;
if (m > 0) {
somx2=sqrt((1.0-x)*(1.0+x));
fact=1.0;
for (i=1;i<=m;i++) {
pmm *= -fact*somx2;
fact += 2.0;
}
}
if (l == m)
return pmm;
else {
pmmp1=x*(2*m+1)*pmm;
if (l == (m+1))
return pmmp1;
else {
for (ll=m+2;ll<=l;ll++) {
pll=(x*(2*ll-1)*pmmp1-(ll+m-1)*pmm)/(ll-m);
pmm=pmmp1;
pmmp1=pll;
}
return pll;
}
}
}
/* (C) Copr. 1986-92 Numerical Recipes Software 9.1-5i. */
|
the_stack_data/111376.c | #include <stdio.h>
// I used infinite loop + break, because code is short and doesn't contain complicated nested loops;
int main() {
int index = 0, even = 0, product, last[3] = {0};
while(1) {
// I used "hardcoded array shifting", because I know exacly size of array and it's small;
last[0] = last[1];
last[1] = last[2];
// I'm using already existing array, because there's nbo need for additional variable;
printf("Provide an integer number: "); scanf("%d", &last[2]); fflush(stdin);
if(index == 0) product = last[2];
else product *= last[2];
if(last[2] % 2 == 0) even++;
index++;
if(product > 1000) {
printf("Product of given numbers exeeded 1000\nQuiting...\n");
break;
}
if(even > 10){
printf("The number of reported even numbers exceed 10\nQuiting...\n"); // it will never occur for positive numbers, because 2^10 > 1000
break;
}
if(last[0] == last[1] && last[1] == last[2]){
printf("Three subsequent numbers had exactly the same value\nQuiting...\n");
break;
}
char yn;
printf("Do you want to finish? [Y/N] : "); scanf(" %c", &yn); fflush(stdin);
if(yn == 'y' || yn == 'Y') break;
}
return 0;
}
|
the_stack_data/103265312.c | /*
* A bare-minimum hello world program.
*
* Copyright (C) 2021 Maxim Rebguns. Licensed under MIT. See the
* LICENSE file for details.
*/
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
|
the_stack_data/242331399.c | #include "math.h"
double tanh(double n) {
return 0.0;
}
|
the_stack_data/78934.c | int doSomething(int arg1, int arg2) {
return arg1 + arg2;
}
int main() {
if (doSomething(2, 3) != 5) {
return 1;
}
return 0;
}
// clang-format off
// RUN: cd / && %clang_cc %sysroot %s -fembed-bitcode -g -o %s.exe
// RUN: cd %CURRENT_DIR
// RUN: unset TERM; %mull_cxx -linker=%clang_cc -linker-flags="%sysroot" -mutators=cxx_add_to_sub -output=%s.mutated-keep.exe -keep-executable %s.exe
// RUN: test -f %s.mutated-keep.exe
// RUN: unset TERM; %mull_cxx -linker=%clang_cc -linker-flags="%sysroot" -mutators=cxx_add_to_sub -output=%s.mutated-delete.exe %s.exe
// RUN: test ! -f %s.mutated-delete.exe |
the_stack_data/62638909.c | #include <stdio.h>
#include <math.h>
#include <stdbool.h>
double bessy0(double x);
double bessy1(double x);
double bessj0(double x);
double bessj1(double x);
double snippet (double n, double x) {
double j =0;
double by = 0;
double bym= 0;
double byp= 0;
double tox= 0;
double temp = 2;//change
if (n < temp)//change
return -1000;
tox=2.0*x;
by=bessy1(x);
bym=bessy0(x);
for (j=1;j<n;j++) {
byp=j*tox*by-bym;
bym=by;
by=byp;
}
return by;
}
double bessy0(double x){
double z,xx,y,ans,ans1,ans2;
if (x < 8.0) {
y=x*x;
ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6
+y*(10879881.29+y*(-86327.92757+y*228.4622733))));
ans2=40076544269.0+y*(745249964.8+y*(7189466.438
+y*(47447.26470+y*(226.1030244+y*1.0))));
ans=(ans1/ans2)+0.636619772*bessj0(x)*log(x);
} else {
z=8.0/x;
y=z*z;
xx=x-0.785398164;
ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4
+y*(-0.2073370639e-5+y*0.2093887211e-6)));
ans2 = -0.1562499995e-1+y*(0.1430488765e-3
+y*(-0.6911147651e-5+y*(0.7621095161e-6
+y*(-0.934945152e-7))));
ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2);
}
return ans;
}
double bessy1(double x){
double z,xx,y,ans,ans1,ans2;
if (x < 8.0) {
y=x*x;
ans1=x*(-0.4900604943e13+y*(0.1275274390e13
+y*(-0.5153438139e11+y*(0.7349264551e9
+y*(-0.4237922726e7+y*0.8511937935e4)))));
ans2=0.2499580570e14+y*(0.4244419664e12
+y*(0.3733650367e10+y*(0.2245904002e8
+y*(0.1020426050e6+y*(0.3549632885e3+y)))));
ans=(ans1/ans2)+0.636619772*(bessj1(x)*log(x)-1.0/x);
} else {
z=8.0/x;
y=z*z;
xx=x-2.356194491;
ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4
+y*(0.2457520174e-5+y*(-0.240337019e-6))));
ans2=0.04687499995+y*(-0.2002690873e-3
+y*(0.8449199096e-5+y*(-0.88228987e-6
+y*0.105787412e-6)));
ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2);
}
return ans;
}
double bessj0(double x){
double ax,z,xx,y,ans,ans1,ans2;
if ((ax=fabs(x)) < 8.0) {
y=x*x;
ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7
+y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
ans2=57568490411.0+y*(1029532985.0+y*(9494680.718
+y*(59272.64853+y*(267.8532712+y*1.0))));
ans=ans1/ans2;
} else {
z=8.0/ax;
y=z*z;
xx=ax-0.785398164;
ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4
+y*(-0.2073370639e-5+y*0.2093887211e-6)));
ans2 = -0.1562499995e-1+y*(0.1430488765e-3
+y*(-0.6911147651e-5+y*(0.7621095161e-6
-y*0.934945152e-7)));
ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
}
return ans;
}
double bessj1(double x){
double ax,z,xx,y,ans,ans1,ans2;
if ((ax=fabs(x)) < 8.0) {
y=x*x;
ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1
+y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
ans2=144725228442.0+y*(2300535178.0+y*(18583304.74
+y*(99447.43394+y*(376.9991397+y*1.0))));
ans=ans1/ans2;
} else {
z=8.0/ax;
y=z*z;
xx=ax-2.356194491;
ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4
+y*(0.2457520174e-5+y*(-0.240337019e-6))));
ans2=0.04687499995+y*(-0.2002690873e-3
+y*(0.8449199096e-5+y*(-0.88228987e-6
+y*0.105787412e-6)));
ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
if (x < 0.0) ans = -ans;
}
return ans;
} |
the_stack_data/140764632.c | #include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
pthread_mutex_t my_mutex;
int global = 0;
void *increment_thread(void *arg) {
int i;
for(i=0; i<10;i++) {
// printf("Before mutex lock: Increment Thread: global = %d\n",global);
pthread_mutex_lock(&my_mutex);
global++;
printf("in mutex lock: Increment Thread: global = %d\n",global);
sleep(2);
pthread_mutex_unlock(&my_mutex);
// printf("After mutex lock: Increment Thread: global = %d\n",global);
sleep(1);
}
pthread_exit(NULL);
}
int main(int argc, char **argv) {
pthread_t thread;
int i;
pthread_mutex_init(&my_mutex, NULL);
if(pthread_create(&thread,NULL,increment_thread,NULL)) {
printf("Failed to create thread. Exiting\n");
return 1;
}
for(i=0; i<10;i++) {
// printf("Before mutex lock: Main Thread: global = %d\n",global);
pthread_mutex_lock(&my_mutex);
global++;
printf("in mutex lock: Main Thread: global = %d\n",global);
sleep(1);
pthread_mutex_unlock(&my_mutex);
// printf("After mutex lock: Main Thread: global = %d\n",global);
sleep(2);
}
pthread_exit(NULL);
}
|
the_stack_data/10376.c | /* f2c.h -- Standard Fortran to C header file */
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
#ifndef F2C_INCLUDE
#define F2C_INCLUDE
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimag(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__13 = 13;
static integer c__15 = 15;
static integer c_n1 = -1;
static integer c__12 = 12;
static integer c__14 = 14;
static integer c__16 = 16;
static logical c_false = FALSE_;
static integer c__1 = 1;
static integer c__3 = 3;
/* > \brief \b SLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Sc
hur decomposition. */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download SLAQR4 + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaqr4.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaqr4.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaqr4.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE SLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI, */
/* ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO ) */
/* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N */
/* LOGICAL WANTT, WANTZ */
/* REAL H( LDH, * ), WI( * ), WORK( * ), WR( * ), */
/* $ Z( LDZ, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > SLAQR4 implements one level of recursion for SLAQR0. */
/* > It is a complete implementation of the small bulge multi-shift */
/* > QR algorithm. It may be called by SLAQR0 and, for large enough */
/* > deflation window size, it may be called by SLAQR3. This */
/* > subroutine is identical to SLAQR0 except that it calls SLAQR2 */
/* > instead of SLAQR3. */
/* > */
/* > SLAQR4 computes the eigenvalues of a Hessenberg matrix H */
/* > and, optionally, the matrices T and Z from the Schur decomposition */
/* > H = Z T Z**T, where T is an upper quasi-triangular matrix (the */
/* > Schur form), and Z is the orthogonal matrix of Schur vectors. */
/* > */
/* > Optionally Z may be postmultiplied into an input orthogonal */
/* > matrix Q so that this routine can give the Schur factorization */
/* > of a matrix A which has been reduced to the Hessenberg form H */
/* > by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] WANTT */
/* > \verbatim */
/* > WANTT is LOGICAL */
/* > = .TRUE. : the full Schur form T is required; */
/* > = .FALSE.: only eigenvalues are required. */
/* > \endverbatim */
/* > */
/* > \param[in] WANTZ */
/* > \verbatim */
/* > WANTZ is LOGICAL */
/* > = .TRUE. : the matrix of Schur vectors Z is required; */
/* > = .FALSE.: Schur vectors are not required. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix H. N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] ILO */
/* > \verbatim */
/* > ILO is INTEGER */
/* > \endverbatim */
/* > */
/* > \param[in] IHI */
/* > \verbatim */
/* > IHI is INTEGER */
/* > It is assumed that H is already upper triangular in rows */
/* > and columns 1:ILO-1 and IHI+1:N and, if ILO > 1, */
/* > H(ILO,ILO-1) is zero. ILO and IHI are normally set by a */
/* > previous call to SGEBAL, and then passed to SGEHRD when the */
/* > matrix output by SGEBAL is reduced to Hessenberg form. */
/* > Otherwise, ILO and IHI should be set to 1 and N, */
/* > respectively. If N > 0, then 1 <= ILO <= IHI <= N. */
/* > If N = 0, then ILO = 1 and IHI = 0. */
/* > \endverbatim */
/* > */
/* > \param[in,out] H */
/* > \verbatim */
/* > H is REAL array, dimension (LDH,N) */
/* > On entry, the upper Hessenberg matrix H. */
/* > On exit, if INFO = 0 and WANTT is .TRUE., then H contains */
/* > the upper quasi-triangular matrix T from the Schur */
/* > decomposition (the Schur form); 2-by-2 diagonal blocks */
/* > (corresponding to complex conjugate pairs of eigenvalues) */
/* > are returned in standard form, with H(i,i) = H(i+1,i+1) */
/* > and H(i+1,i)*H(i,i+1) < 0. If INFO = 0 and WANTT is */
/* > .FALSE., then the contents of H are unspecified on exit. */
/* > (The output value of H when INFO > 0 is given under the */
/* > description of INFO below.) */
/* > */
/* > This subroutine may explicitly set H(i,j) = 0 for i > j and */
/* > j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N. */
/* > \endverbatim */
/* > */
/* > \param[in] LDH */
/* > \verbatim */
/* > LDH is INTEGER */
/* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[out] WR */
/* > \verbatim */
/* > WR is REAL array, dimension (IHI) */
/* > \endverbatim */
/* > */
/* > \param[out] WI */
/* > \verbatim */
/* > WI is REAL array, dimension (IHI) */
/* > The real and imaginary parts, respectively, of the computed */
/* > eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI) */
/* > and WI(ILO:IHI). If two eigenvalues are computed as a */
/* > complex conjugate pair, they are stored in consecutive */
/* > elements of WR and WI, say the i-th and (i+1)th, with */
/* > WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., then */
/* > the eigenvalues are stored in the same order as on the */
/* > diagonal of the Schur form returned in H, with */
/* > WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal */
/* > block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and */
/* > WI(i+1) = -WI(i). */
/* > \endverbatim */
/* > */
/* > \param[in] ILOZ */
/* > \verbatim */
/* > ILOZ is INTEGER */
/* > \endverbatim */
/* > */
/* > \param[in] IHIZ */
/* > \verbatim */
/* > IHIZ is INTEGER */
/* > Specify the rows of Z to which transformations must be */
/* > applied if WANTZ is .TRUE.. */
/* > 1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
/* > \endverbatim */
/* > */
/* > \param[in,out] Z */
/* > \verbatim */
/* > Z is REAL array, dimension (LDZ,IHI) */
/* > If WANTZ is .FALSE., then Z is not referenced. */
/* > If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is */
/* > replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the */
/* > orthogonal Schur factor of H(ILO:IHI,ILO:IHI). */
/* > (The output value of Z when INFO > 0 is given under */
/* > the description of INFO below.) */
/* > \endverbatim */
/* > */
/* > \param[in] LDZ */
/* > \verbatim */
/* > LDZ is INTEGER */
/* > The leading dimension of the array Z. if WANTZ is .TRUE. */
/* > then LDZ >= MAX(1,IHIZ). Otherwise, LDZ >= 1. */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is REAL array, dimension LWORK */
/* > On exit, if LWORK = -1, WORK(1) returns an estimate of */
/* > the optimal value for LWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LWORK */
/* > \verbatim */
/* > LWORK is INTEGER */
/* > The dimension of the array WORK. LWORK >= f2cmax(1,N) */
/* > is sufficient, but LWORK typically as large as 6*N may */
/* > be required for optimal performance. A workspace query */
/* > to determine the optimal workspace size is recommended. */
/* > */
/* > If LWORK = -1, then SLAQR4 does a workspace query. */
/* > In this case, SLAQR4 checks the input parameters and */
/* > estimates the optimal workspace size for the given */
/* > values of N, ILO and IHI. The estimate is returned */
/* > in WORK(1). No error message related to LWORK is */
/* > issued by XERBLA. Neither H nor Z are accessed. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > > 0: if INFO = i, SLAQR4 failed to compute all of */
/* > the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */
/* > and WI contain those eigenvalues which have been */
/* > successfully computed. (Failures are rare.) */
/* > */
/* > If INFO > 0 and WANT is .FALSE., then on exit, */
/* > the remaining unconverged eigenvalues are the eigen- */
/* > values of the upper Hessenberg matrix rows and */
/* > columns ILO through INFO of the final, output */
/* > value of H. */
/* > */
/* > If INFO > 0 and WANTT is .TRUE., then on exit */
/* > */
/* > (*) (initial value of H)*U = U*(final value of H) */
/* > */
/* > where U is a orthogonal matrix. The final */
/* > value of H is upper Hessenberg and triangular in */
/* > rows and columns INFO+1 through IHI. */
/* > */
/* > If INFO > 0 and WANTZ is .TRUE., then on exit */
/* > */
/* > (final value of Z(ILO:IHI,ILOZ:IHIZ) */
/* > = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U */
/* > */
/* > where U is the orthogonal matrix in (*) (regard- */
/* > less of the value of WANTT.) */
/* > */
/* > If INFO > 0 and WANTZ is .FALSE., then Z is not */
/* > accessed. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup realOTHERauxiliary */
/* > \par Contributors: */
/* ================== */
/* > */
/* > Karen Braman and Ralph Byers, Department of Mathematics, */
/* > University of Kansas, USA */
/* > \par References: */
/* ================ */
/* > */
/* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
/* > Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
/* > Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
/* > 929--947, 2002. */
/* > \n */
/* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
/* > Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
/* > of Matrix Analysis, volume 23, pages 948--973, 2002. */
/* > */
/* ===================================================================== */
/* Subroutine */ int slaqr4_(logical *wantt, logical *wantz, integer *n,
integer *ilo, integer *ihi, real *h__, integer *ldh, real *wr, real *
wi, integer *iloz, integer *ihiz, real *z__, integer *ldz, real *work,
integer *lwork, integer *info)
{
/* System generated locals */
integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
real r__1, r__2, r__3, r__4;
/* Local variables */
integer ndec, ndfl, kbot, nmin;
real swap;
integer ktop;
real zdum[1] /* was [1][1] */;
integer kacc22, i__, k, itmax, nsmax, nwmax, kwtop;
real aa, bb;
extern /* Subroutine */ int slanv2_(real *, real *, real *, real *, real *
, real *, real *, real *, real *, real *);
real cc, dd;
extern /* Subroutine */ int slaqr2_(logical *, logical *, integer *,
integer *, integer *, integer *, real *, integer *, integer *,
integer *, real *, integer *, integer *, integer *, real *, real *
, real *, integer *, integer *, real *, integer *, integer *,
real *, integer *, real *, integer *), slaqr5_(logical *, logical
*, integer *, integer *, integer *, integer *, integer *, real *,
real *, real *, integer *, integer *, integer *, real *, integer *
, real *, integer *, real *, integer *, integer *, real *,
integer *, integer *, real *, integer *);
integer ld;
real cs;
integer nh, nibble, it, ks, kt;
real sn;
integer ku, kv, ls, ns;
real ss;
integer nw;
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
integer *, integer *, ftnlen, ftnlen);
char jbcmpz[2];
extern /* Subroutine */ int slahqr_(logical *, logical *, integer *,
integer *, integer *, real *, integer *, real *, real *, integer *
, integer *, real *, integer *, integer *), slacpy_(char *,
integer *, integer *, real *, integer *, real *, integer *);
integer nwupbd;
logical sorted;
integer lwkopt, inf, kdu, nho, nve, kwh, nsr, nwr, kwv;
/* -- LAPACK auxiliary routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ================================================================ */
/* ==== Matrices of order NTINY or smaller must be processed by */
/* . SLAHQR because of insufficient subdiagonal scratch space. */
/* . (This is a hard limit.) ==== */
/* ==== Exceptional deflation windows: try to cure rare */
/* . slow convergence by varying the size of the */
/* . deflation window after KEXNW iterations. ==== */
/* ==== Exceptional shifts: try to cure rare slow convergence */
/* . with ad-hoc exceptional shifts every KEXSH iterations. */
/* . ==== */
/* ==== The constants WILK1 and WILK2 are used to form the */
/* . exceptional shifts. ==== */
/* Parameter adjustments */
h_dim1 = *ldh;
h_offset = 1 + h_dim1 * 1;
h__ -= h_offset;
--wr;
--wi;
z_dim1 = *ldz;
z_offset = 1 + z_dim1 * 1;
z__ -= z_offset;
--work;
/* Function Body */
*info = 0;
/* ==== Quick return for N = 0: nothing to do. ==== */
if (*n == 0) {
work[1] = 1.f;
return 0;
}
if (*n <= 15) {
/* ==== Tiny matrices must use SLAHQR. ==== */
lwkopt = 1;
if (*lwork != -1) {
slahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &
wi[1], iloz, ihiz, &z__[z_offset], ldz, info);
}
} else {
/* ==== Use small bulge multi-shift QR with aggressive early */
/* . deflation on larger-than-tiny matrices. ==== */
/* ==== Hope for the best. ==== */
*info = 0;
/* ==== Set up job flags for ILAENV. ==== */
if (*wantt) {
*(unsigned char *)jbcmpz = 'S';
} else {
*(unsigned char *)jbcmpz = 'E';
}
if (*wantz) {
*(unsigned char *)&jbcmpz[1] = 'V';
} else {
*(unsigned char *)&jbcmpz[1] = 'N';
}
/* ==== NWR = recommended deflation window size. At this */
/* . point, N .GT. NTINY = 15, so there is enough */
/* . subdiagonal workspace for NWR.GE.2 as required. */
/* . (In fact, there is enough subdiagonal space for */
/* . NWR.GE.4.) ==== */
nwr = ilaenv_(&c__13, "SLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
(ftnlen)2);
nwr = f2cmax(2,nwr);
/* Computing MIN */
i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = f2cmin(i__1,i__2);
nwr = f2cmin(i__1,nwr);
/* ==== NSR = recommended number of simultaneous shifts. */
/* . At this point N .GT. NTINY = 15, so there is at */
/* . enough subdiagonal workspace for NSR to be even */
/* . and greater than or equal to two as required. ==== */
nsr = ilaenv_(&c__15, "SLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
(ftnlen)2);
/* Computing MIN */
i__1 = nsr, i__2 = (*n - 3) / 6, i__1 = f2cmin(i__1,i__2), i__2 = *ihi -
*ilo;
nsr = f2cmin(i__1,i__2);
/* Computing MAX */
i__1 = 2, i__2 = nsr - nsr % 2;
nsr = f2cmax(i__1,i__2);
/* ==== Estimate optimal workspace ==== */
/* ==== Workspace query call to SLAQR2 ==== */
i__1 = nwr + 1;
slaqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1], &h__[
h_offset], ldh, n, &h__[h_offset], ldh, n, &h__[h_offset],
ldh, &work[1], &c_n1);
/* ==== Optimal workspace = MAX(SLAQR5, SLAQR2) ==== */
/* Computing MAX */
i__1 = nsr * 3 / 2, i__2 = (integer) work[1];
lwkopt = f2cmax(i__1,i__2);
/* ==== Quick return in case of workspace query. ==== */
if (*lwork == -1) {
work[1] = (real) lwkopt;
return 0;
}
/* ==== SLAHQR/SLAQR0 crossover point ==== */
nmin = ilaenv_(&c__12, "SLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
6, (ftnlen)2);
nmin = f2cmax(15,nmin);
/* ==== Nibble crossover point ==== */
nibble = ilaenv_(&c__14, "SLAQR4", jbcmpz, n, ilo, ihi, lwork, (
ftnlen)6, (ftnlen)2);
nibble = f2cmax(0,nibble);
/* ==== Accumulate reflections during ttswp? Use block */
/* . 2-by-2 structure during matrix-matrix multiply? ==== */
kacc22 = ilaenv_(&c__16, "SLAQR4", jbcmpz, n, ilo, ihi, lwork, (
ftnlen)6, (ftnlen)2);
kacc22 = f2cmax(0,kacc22);
kacc22 = f2cmin(2,kacc22);
/* ==== NWMAX = the largest possible deflation window for */
/* . which there is sufficient workspace. ==== */
/* Computing MIN */
i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
nwmax = f2cmin(i__1,i__2);
nw = nwmax;
/* ==== NSMAX = the Largest number of simultaneous shifts */
/* . for which there is sufficient workspace. ==== */
/* Computing MIN */
i__1 = (*n - 3) / 6, i__2 = (*lwork << 1) / 3;
nsmax = f2cmin(i__1,i__2);
nsmax -= nsmax % 2;
/* ==== NDFL: an iteration count restarted at deflation. ==== */
ndfl = 1;
/* ==== ITMAX = iteration limit ==== */
/* Computing MAX */
i__1 = 10, i__2 = *ihi - *ilo + 1;
itmax = 30 * f2cmax(i__1,i__2);
/* ==== Last row and column in the active block ==== */
kbot = *ihi;
/* ==== Main Loop ==== */
i__1 = itmax;
for (it = 1; it <= i__1; ++it) {
/* ==== Done when KBOT falls below ILO ==== */
if (kbot < *ilo) {
goto L90;
}
/* ==== Locate active block ==== */
i__2 = *ilo + 1;
for (k = kbot; k >= i__2; --k) {
if (h__[k + (k - 1) * h_dim1] == 0.f) {
goto L20;
}
/* L10: */
}
k = *ilo;
L20:
ktop = k;
/* ==== Select deflation window size: */
/* . Typical Case: */
/* . If possible and advisable, nibble the entire */
/* . active block. If not, use size MIN(NWR,NWMAX) */
/* . or MIN(NWR+1,NWMAX) depending upon which has */
/* . the smaller corresponding subdiagonal entry */
/* . (a heuristic). */
/* . */
/* . Exceptional Case: */
/* . If there have been no deflations in KEXNW or */
/* . more iterations, then vary the deflation window */
/* . size. At first, because, larger windows are, */
/* . in general, more powerful than smaller ones, */
/* . rapidly increase the window to the maximum possible. */
/* . Then, gradually reduce the window size. ==== */
nh = kbot - ktop + 1;
nwupbd = f2cmin(nh,nwmax);
if (ndfl < 5) {
nw = f2cmin(nwupbd,nwr);
} else {
/* Computing MIN */
i__2 = nwupbd, i__3 = nw << 1;
nw = f2cmin(i__2,i__3);
}
if (nw < nwmax) {
if (nw >= nh - 1) {
nw = nh;
} else {
kwtop = kbot - nw + 1;
if ((r__1 = h__[kwtop + (kwtop - 1) * h_dim1], abs(r__1))
> (r__2 = h__[kwtop - 1 + (kwtop - 2) * h_dim1],
abs(r__2))) {
++nw;
}
}
}
if (ndfl < 5) {
ndec = -1;
} else if (ndec >= 0 || nw >= nwupbd) {
++ndec;
if (nw - ndec < 2) {
ndec = 0;
}
nw -= ndec;
}
/* ==== Aggressive early deflation: */
/* . split workspace under the subdiagonal into */
/* . - an nw-by-nw work array V in the lower */
/* . left-hand-corner, */
/* . - an NW-by-at-least-NW-but-more-is-better */
/* . (NW-by-NHO) horizontal work array along */
/* . the bottom edge, */
/* . - an at-least-NW-but-more-is-better (NHV-by-NW) */
/* . vertical work array along the left-hand-edge. */
/* . ==== */
kv = *n - nw + 1;
kt = nw + 1;
nho = *n - nw - 1 - kt + 1;
kwv = nw + 2;
nve = *n - nw - kwv + 1;
/* ==== Aggressive early deflation ==== */
slaqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1],
&h__[kv + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1],
ldh, &nve, &h__[kwv + h_dim1], ldh, &work[1], lwork);
/* ==== Adjust KBOT accounting for new deflations. ==== */
kbot -= ld;
/* ==== KS points to the shifts. ==== */
ks = kbot - ls + 1;
/* ==== Skip an expensive QR sweep if there is a (partly */
/* . heuristic) reason to expect that many eigenvalues */
/* . will deflate without it. Here, the QR sweep is */
/* . skipped if many eigenvalues have just been deflated */
/* . or if the remaining active block is small. */
if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > f2cmin(
nmin,nwmax)) {
/* ==== NS = nominal number of simultaneous shifts. */
/* . This may be lowered (slightly) if SLAQR2 */
/* . did not provide that many shifts. ==== */
/* Computing MIN */
/* Computing MAX */
i__4 = 2, i__5 = kbot - ktop;
i__2 = f2cmin(nsmax,nsr), i__3 = f2cmax(i__4,i__5);
ns = f2cmin(i__2,i__3);
ns -= ns % 2;
/* ==== If there have been no deflations */
/* . in a multiple of KEXSH iterations, */
/* . then try exceptional shifts. */
/* . Otherwise use shifts provided by */
/* . SLAQR2 above or from the eigenvalues */
/* . of a trailing principal submatrix. ==== */
if (ndfl % 6 == 0) {
ks = kbot - ns + 1;
/* Computing MAX */
i__3 = ks + 1, i__4 = ktop + 2;
i__2 = f2cmax(i__3,i__4);
for (i__ = kbot; i__ >= i__2; i__ += -2) {
ss = (r__1 = h__[i__ + (i__ - 1) * h_dim1], abs(r__1))
+ (r__2 = h__[i__ - 1 + (i__ - 2) * h_dim1],
abs(r__2));
aa = ss * .75f + h__[i__ + i__ * h_dim1];
bb = ss;
cc = ss * -.4375f;
dd = aa;
slanv2_(&aa, &bb, &cc, &dd, &wr[i__ - 1], &wi[i__ - 1]
, &wr[i__], &wi[i__], &cs, &sn);
/* L30: */
}
if (ks == ktop) {
wr[ks + 1] = h__[ks + 1 + (ks + 1) * h_dim1];
wi[ks + 1] = 0.f;
wr[ks] = wr[ks + 1];
wi[ks] = wi[ks + 1];
}
} else {
/* ==== Got NS/2 or fewer shifts? Use SLAHQR */
/* . on a trailing principal submatrix to */
/* . get more. (Since NS.LE.NSMAX.LE.(N-3)/6, */
/* . there is enough space below the subdiagonal */
/* . to fit an NS-by-NS scratch array.) ==== */
if (kbot - ks + 1 <= ns / 2) {
ks = kbot - ns + 1;
kt = *n - ns + 1;
slacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
h__[kt + h_dim1], ldh);
slahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt
+ h_dim1], ldh, &wr[ks], &wi[ks], &c__1, &
c__1, zdum, &c__1, &inf);
ks += inf;
/* ==== In case of a rare QR failure use */
/* . eigenvalues of the trailing 2-by-2 */
/* . principal submatrix. ==== */
if (ks >= kbot) {
aa = h__[kbot - 1 + (kbot - 1) * h_dim1];
cc = h__[kbot + (kbot - 1) * h_dim1];
bb = h__[kbot - 1 + kbot * h_dim1];
dd = h__[kbot + kbot * h_dim1];
slanv2_(&aa, &bb, &cc, &dd, &wr[kbot - 1], &wi[
kbot - 1], &wr[kbot], &wi[kbot], &cs, &sn)
;
ks = kbot - 1;
}
}
if (kbot - ks + 1 > ns) {
/* ==== Sort the shifts (Helps a little) */
/* . Bubble sort keeps complex conjugate */
/* . pairs together. ==== */
sorted = FALSE_;
i__2 = ks + 1;
for (k = kbot; k >= i__2; --k) {
if (sorted) {
goto L60;
}
sorted = TRUE_;
i__3 = k - 1;
for (i__ = ks; i__ <= i__3; ++i__) {
if ((r__1 = wr[i__], abs(r__1)) + (r__2 = wi[
i__], abs(r__2)) < (r__3 = wr[i__ + 1]
, abs(r__3)) + (r__4 = wi[i__ + 1],
abs(r__4))) {
sorted = FALSE_;
swap = wr[i__];
wr[i__] = wr[i__ + 1];
wr[i__ + 1] = swap;
swap = wi[i__];
wi[i__] = wi[i__ + 1];
wi[i__ + 1] = swap;
}
/* L40: */
}
/* L50: */
}
L60:
;
}
/* ==== Shuffle shifts into pairs of real shifts */
/* . and pairs of complex conjugate shifts */
/* . assuming complex conjugate shifts are */
/* . already adjacent to one another. (Yes, */
/* . they are.) ==== */
i__2 = ks + 2;
for (i__ = kbot; i__ >= i__2; i__ += -2) {
if (wi[i__] != -wi[i__ - 1]) {
swap = wr[i__];
wr[i__] = wr[i__ - 1];
wr[i__ - 1] = wr[i__ - 2];
wr[i__ - 2] = swap;
swap = wi[i__];
wi[i__] = wi[i__ - 1];
wi[i__ - 1] = wi[i__ - 2];
wi[i__ - 2] = swap;
}
/* L70: */
}
}
/* ==== If there are only two shifts and both are */
/* . real, then use only one. ==== */
if (kbot - ks + 1 == 2) {
if (wi[kbot] == 0.f) {
if ((r__1 = wr[kbot] - h__[kbot + kbot * h_dim1], abs(
r__1)) < (r__2 = wr[kbot - 1] - h__[kbot +
kbot * h_dim1], abs(r__2))) {
wr[kbot - 1] = wr[kbot];
} else {
wr[kbot] = wr[kbot - 1];
}
}
}
/* ==== Use up to NS of the the smallest magnitude */
/* . shifts. If there aren't NS shifts available, */
/* . then use them all, possibly dropping one to */
/* . make the number of shifts even. ==== */
/* Computing MIN */
i__2 = ns, i__3 = kbot - ks + 1;
ns = f2cmin(i__2,i__3);
ns -= ns % 2;
ks = kbot - ns + 1;
/* ==== Small-bulge multi-shift QR sweep: */
/* . split workspace under the subdiagonal into */
/* . - a KDU-by-KDU work array U in the lower */
/* . left-hand-corner, */
/* . - a KDU-by-at-least-KDU-but-more-is-better */
/* . (KDU-by-NHo) horizontal work array WH along */
/* . the bottom edge, */
/* . - and an at-least-KDU-but-more-is-better-by-KDU */
/* . (NVE-by-KDU) vertical work WV arrow along */
/* . the left-hand-edge. ==== */
kdu = ns << 1;
ku = *n - kdu + 1;
kwh = kdu + 1;
nho = *n - kdu - 3 - (kdu + 1) + 1;
kwv = kdu + 4;
nve = *n - kdu - kwv + 1;
/* ==== Small-bulge multi-shift QR sweep ==== */
slaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &wr[ks],
&wi[ks], &h__[h_offset], ldh, iloz, ihiz, &z__[
z_offset], ldz, &work[1], &c__3, &h__[ku + h_dim1],
ldh, &nve, &h__[kwv + h_dim1], ldh, &nho, &h__[ku +
kwh * h_dim1], ldh);
}
/* ==== Note progress (or the lack of it). ==== */
if (ld > 0) {
ndfl = 1;
} else {
++ndfl;
}
/* ==== End of main loop ==== */
/* L80: */
}
/* ==== Iteration limit exceeded. Set INFO to show where */
/* . the problem occurred and exit. ==== */
*info = kbot;
L90:
;
}
/* ==== Return the optimal value of LWORK. ==== */
work[1] = (real) lwkopt;
/* ==== End of SLAQR4 ==== */
return 0;
} /* slaqr4_ */
|
the_stack_data/37430.c | struct does_not_fit_in_a_reg {
char f0_0;
char f1_0;
char f2_0;
char f3_0;
int i4_0;
long long l5_1;
long long l6_2;
long long l7_3;
long long l8_4;
};
int check_args_are_correct(int a0, struct does_not_fit_in_a_reg s1234, int a5,
int a6);
int check_args_are_correct_user(int a0, struct does_not_fit_in_a_reg s1234,
int a5, int a6) {
return a0 == 0 && s1234.f0_0 == (char)0xCC && s1234.f1_0 == (char)0xDD &&
s1234.f2_0 == (char)0xEE && s1234.f3_0 == (char)0xFF &&
s1234.i4_0 == (int)0xdeadbeef &&
s1234.l5_1 == (long long)0xAABBCCDDEEFF0102ULL &&
s1234.l6_2 == (long long)0x0304050607080910ULL &&
s1234.l7_3 == (long long)0x1112131415161718ULL &&
s1234.l8_4 == (long long)0x4444444444444444ULL && a5 == 2 && a6 == 3;
}
int main(int argc, char **argv) {
struct does_not_fit_in_a_reg s1234 = {0xCC,
0xDD,
0xEE,
0xFF,
0xdeadbeef,
0xAABBCCDDEEFF0102ULL,
0x0304050607080910ULL,
0x1112131415161718ULL,
0x4444444444444444ULL};
// CHECK r0 0
// CHECK_RELATIVE r1:0 0xdeadbeefffeeddcc
// CHECK_RELATIVE r1:8 0xAABBCCDDEEFF0102
// CHECK_RELATIVE r1:16 0x0304050607080910
// CHECK_RELATIVE r1:24 0x1112131415161718
// CHECK_RELATIVE r1:32 0x4444444444444444
// CHECK r2 2
// CHECK r3 3
return !check_args_are_correct(0, s1234, 2, 3);
}
|
the_stack_data/242330011.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define FILENAME "input.txt"
#define MAX_LINE_LENGTH 12
#define MAX_LINES 1000
#define BINARY_REFERENCE 0b111111111111 // as many 1s as MAX_LINE_LENGTH
char** readFile(char fileName[])
{
int i, j, lines, lineLength;
FILE *fp; // declare file pointer
fp = fopen(fileName, "r"); // open file
lines = MAX_LINES + 1;
lineLength = MAX_LINE_LENGTH + 2;
/* Create array and allocate memory */
char ** file = malloc(lines * sizeof(char*));
for (i = 0; i < lines; i++)
file[i] = malloc (lineLength * sizeof(char));
char line[lineLength];
/* Prefill with empty characters */
for (i = 0; i < lines; i++)
for (j = 0; j < lineLength; j++)
file[i][j] = '\0';
for (i = 0; i < lineLength; i++)
line[i] = '\0';
/* check for empty file */
if (fp != NULL)
{
i = 0;
while (fgets(line, sizeof line, fp) != NULL)
{
/* read line and check for increases */
strcpy(file[i], line);
// printf("Line %d: %s", i, line);
i++;
}
fclose(fp);
}
else
{
/* Error handling */
return 0;
}
return file;
}
unsigned int calcGamma(char** file)
{
int i, j, bit;
char gammaRate[MAX_LINE_LENGTH];
if (file)
{
/* Determine gamma rate */
for (i = 0; i < MAX_LINE_LENGTH; i++) {
bit = 0;
for (j = 0; j < MAX_LINES; j++) {
if (file[j][i] - '0' >= 0)
bit += file[j][i] - '0';
}
gammaRate[i] = round((double)bit / MAX_LINES) + '0';
}
printf("Gamma rate (binary): %s\n", gammaRate);
}
else
{
/* Error handling */
return 0;
}
return strtol(gammaRate, NULL, 2);
}
char* intToBinary(int integer) {
// based on answer by @chux at https://codereview.stackexchange.com/questions/255036/represent-integer-as-binary-in-c
int i;
char *binary = malloc(MAX_LINE_LENGTH * sizeof(char));
for (i = MAX_LINE_LENGTH; --i >= 0; ) {
binary[i] = '0' + (integer & 1);
integer /= 2;
}
return binary;
}
unsigned int calcEpsilon(unsigned int gammaRate)
{
int epsilonRate = gammaRate ^ BINARY_REFERENCE;
printf("Gamma rate (binary): %s\n", intToBinary(epsilonRate));
return epsilonRate;
}
int main(void)
{
char** file = readFile((char *)FILENAME);
unsigned int gammaRate = calcGamma(file);
printf("Gamma rate integer: %d\n", gammaRate);
unsigned int epsilonRate = calcEpsilon(gammaRate);
printf("Epsilon rate integer: %d\n", epsilonRate);
printf("Final result: %d\n", gammaRate * epsilonRate);
free(file);
return 1;
} |
the_stack_data/168892978.c | #include <stdio.h>
int main()
{
puts("hello world");
return 0;
}
|
the_stack_data/165765955.c | #include<stdio.h>
int main(void) {
int x = 5, *z = &x;
*z = *z + 3;
z++;
x++;
printf("%d\n",x);
return 0;
}
|
the_stack_data/14199573.c | //void WinningCat() {
// MoveCurTo(gameData.numberOfLines + 7, 34); print(" ∧,,∧");
// MoveCurTo(gameData.numberOfLines + 8, 34); print(" ☆二 ⊂(・ω・`)");
// MoveCurTo(gameData.numberOfLines + 9, 34); print(" -ヽ と)");
// MoveCurTo(gameData.numberOfLines + 10, 34); print(" `u-u'");
//}
//
//void DeadPageInit() {
// PrintCentered("You Are Dead (ó﹏ò。) \r\n\n", gameData.numberOfLines + 6, 19);
//}
|
the_stack_data/67878.c | #include <assert.h>
#include <syslog.h>
int main()
{
closelog();
assert(0);
return 0;
}
|
the_stack_data/106403.c | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern char** environ;
#define STRING_COUNT 3
int main(int argc, char* argv[argc]) {
char** env_var = environ;
const char* expected_strings[] = { "FOO=BAR", "BAR=BAZ", "BAZ=FOO" };
bool was_found[] = { false, false, false };
for (char** cursor = environ; *(cursor) != NULL; cursor++) {
for (int i = 0; i < STRING_COUNT; i++) {
if (!was_found[i]) {
if (strcmp(*cursor, expected_strings[i]) == 0) {
was_found[i] = true;
}
}
}
}
for (int i = 0; i < STRING_COUNT; i++) {
if (was_found[i] == false) {
exit(EXIT_FAILURE);
}
}
exit(EXIT_SUCCESS);
}
|
the_stack_data/48576558.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float libras, kg;
printf("----CONVERSAO DE LIBRAS PARA KG----\n");
printf("Insira o valor de massa em Libras: ");
scanf("%f", &libras);
kg = libras*0.45;
printf("\nO valor da massa inserida convertida para KG eh de: %.2f\n", kg);
return 0;
}
|
the_stack_data/121345.c | /* Selection Sort implementation in C;
* Author : Felipe Gabriel;
* Input : Array lenght and elements;
* Output : Sorted array elements;
*/
#include <stdio.h>
void selection_sort(int size, int *v){
int i, j, min, aux;
for (i = 0; i < (size-1); i++){
min = i;
for (j = (i+1); j < size; j++) {
if(v[j] < v[min]){
min = j;
}
}
if (v[i] != v[min]) {
aux = v[i];
v[i] = v[min];
v[min] = aux;
}
}
}
int main(){
int size,j;
scanf("%d",&size);
int v[size];
for(j = 0; j < size; j++){
scanf("%d",&v[j]);
}
selection_sort(size,v);
for(j = 0; j < size; j++){
if(j != size-1){
printf("%d ",v[j]);
}
else{
printf("%d\n",v[j]);
}
}
return 0;
} |
the_stack_data/184518779.c | #include<stdio.h>
int main()
{
int i,j,n;
printf("no of life:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
|
the_stack_data/82950202.c | /**
******************************************************************************
* @file stm32u5xx_ll_icache.c
* @author MCD Application Team
* @brief ICACHE LL module driver.
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32u5xx_ll_icache.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
/** @addtogroup STM32U5xx_LL_Driver
* @{
*/
#if defined(ICACHE)
/** @defgroup ICACHE_LL ICACHE
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup ICACHE_LL_Private_Macros ICACHE Private Macros
* @{
*/
#define IS_LL_ICACHE_REGION(__VALUE__) (((__VALUE__) == LL_ICACHE_REGION_0) || \
((__VALUE__) == LL_ICACHE_REGION_1) || \
((__VALUE__) == LL_ICACHE_REGION_2) || \
((__VALUE__) == LL_ICACHE_REGION_3))
#define IS_LL_ICACHE_REGION_SIZE(__VALUE__) (((__VALUE__) == LL_ICACHE_REGIONSIZE_2MB) || \
((__VALUE__) == LL_ICACHE_REGIONSIZE_4MB) || \
((__VALUE__) == LL_ICACHE_REGIONSIZE_8MB) || \
((__VALUE__) == LL_ICACHE_REGIONSIZE_16MB) || \
((__VALUE__) == LL_ICACHE_REGIONSIZE_32MB) || \
((__VALUE__) == LL_ICACHE_REGIONSIZE_64MB) || \
((__VALUE__) == LL_ICACHE_REGIONSIZE_128MB))
#define IS_LL_ICACHE_MASTER_PORT(__VALUE__) (((__VALUE__) == LL_ICACHE_MASTER1_PORT) || \
((__VALUE__) == LL_ICACHE_MASTER2_PORT))
#define IS_LL_ICACHE_OUTPUT_BURST(__VALUE__) (((__VALUE__) == LL_ICACHE_OUTPUT_BURST_WRAP) || \
((__VALUE__) == LL_ICACHE_OUTPUT_BURST_INCR))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup ICACHE_LL_Exported_Functions
* @{
*/
/** @addtogroup ICACHE_LL_EF_REGION_Init
* @{
*/
/**
* @brief Configure and enable the memory remapped region.
* @note The Instruction Cache and corresponding region must be disabled.
* @param Region This parameter can be one of the following values:
* @arg @ref LL_ICACHE_REGION_0
* @arg @ref LL_ICACHE_REGION_1
* @arg @ref LL_ICACHE_REGION_2
* @arg @ref LL_ICACHE_REGION_3
* @param pICACHE_RegionStruct pointer to a @ref LL_ICACHE_RegionTypeDef structure.
* @retval None
*/
void LL_ICACHE_ConfigRegion(uint32_t Region, const LL_ICACHE_RegionTypeDef *const pICACHE_RegionStruct)
{
__IO uint32_t *p_reg;
uint32_t value;
/* Check the parameters */
assert_param(IS_LL_ICACHE_REGION(Region));
assert_param(IS_LL_ICACHE_REGION_SIZE(pICACHE_RegionStruct->Size));
assert_param(IS_LL_ICACHE_MASTER_PORT(pICACHE_RegionStruct->TrafficRoute));
assert_param(IS_LL_ICACHE_OUTPUT_BURST(pICACHE_RegionStruct->OutputBurstType));
/* Get region control register address */
p_reg = &(ICACHE->CRR0) + (1U * Region);
/* Region 2MB: BaseAddress size 8 bits, RemapAddress size 11 bits */
/* Region 4MB: BaseAddress size 7 bits, RemapAddress size 10 bits */
/* Region 8MB: BaseAddress size 6 bits, RemapAddress size 9 bits */
/* Region 16MB: BaseAddress size 5 bits, RemapAddress size 8 bits */
/* Region 32MB: BaseAddress size 4 bits, RemapAddress size 7 bits */
/* Region 64MB: BaseAddress size 3 bits, RemapAddress size 6 bits */
/* Region 128MB: BaseAddress size 2 bits, RemapAddress size 5 bits */
value = ((pICACHE_RegionStruct->BaseAddress & 0x1FFFFFFFU) >> 21U) & \
(0xFFU & ~(pICACHE_RegionStruct->Size - 1U));
value |= ((pICACHE_RegionStruct->RemapAddress >> 5U) & \
((uint32_t)(0x7FFU & ~(pICACHE_RegionStruct->Size - 1U)) << ICACHE_CRRx_REMAPADDR_Pos));
value |= (pICACHE_RegionStruct->Size << ICACHE_CRRx_RSIZE_Pos) | pICACHE_RegionStruct->TrafficRoute | \
pICACHE_RegionStruct->OutputBurstType;
*p_reg = (value | ICACHE_CRRx_REN); /* Configure and enable region */
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* ICACHE */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
|
the_stack_data/76699573.c | // A basic clang -cc1 command-line, and simple environment check.
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=CC1 %s
// CC1: clang{{.*}} "-cc1" "-triple" "msp430"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 \
// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430 %s
// MSP430: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
// MSP430: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
// MSP430: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtbegin.o"
// MSP430: "--start-group" "-lmul_none" "-lgcc" "-lc" "-lcrt" "-lnosys" "--end-group"
// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtend.o"
// MSP430: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crtn.o"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nodefaultlibs \
// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-NO-DFT-LIB %s
// MSP430-NO-DFT-LIB: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
// MSP430-NO-DFT-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
// MSP430-NO-DFT-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crt0.o"
// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtbegin.o"
// MSP430-NO-DFT-LIB: "--start-group" "-lmul_none" "-lgcc" "--end-group"
// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430{{/|\\\\}}crtend.o"
// MSP430-NO-DFT-LIB: "{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430{{/|\\\\}}crtn.o"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nostartfiles \
// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-NO-START %s
// MSP430-NO-START: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
// MSP430-NO-START: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
// MSP430-NO-START: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
// MSP430-NO-START: "--start-group" "-lmul_none" "-lgcc" "-lc" "-lcrt" "-lnosys" "--end-group"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -nostdlib \
// RUN: --gcc-toolchain=%S/Inputs/basic_msp430_tree --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-NO-STD-LIB %s
// MSP430-NO-STD-LIB: "{{.*}}Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}msp430-elf-ld"
// MSP430-NO-STD-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/430"
// MSP430-NO-STD-LIB: "-L{{.*}}/Inputs/basic_msp430_tree/lib/gcc/msp430-elf/7.3.1/../../..{{/|\\\\}}..{{/|\\\\}}msp430-elf{{/|\\\\}}lib/430"
// MSP430-NO-STD-LIB: "--start-group" "-lmul_none" "-lgcc" "--end-group"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f147 --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-16BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f147 -mhwmult=auto --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-16BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=16bit --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-16BIT %s
// MSP430-HWMult-16BIT: "--start-group" "-lmul_16"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f4783 --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-32BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mmcu=msp430f4783 -mhwmult=auto --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-32BIT %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=32bit --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-32BIT %s
// MSP430-HWMult-32BIT: "--start-group" "-lmul_32"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=f5series --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-F5 %s
// MSP430-HWMult-F5: "--start-group" "-lmul_f5"
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=none --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-NONE %s
// RUN: %clang %s -### -no-canonical-prefixes -target msp430 -mhwmult=none -mmcu=msp430f4783 --sysroot="" 2>&1 \
// RUN: | FileCheck -check-prefix=MSP430-HWMult-NONE %s
// MSP430-HWMult-NONE: "--start-group" "-lmul_none"
|
the_stack_data/149907.c | /* Exercise 4-11
*
* Modify getop so that it doesn't need to use ungetch. Hint: use an
* internal static variable.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXOP 100
#define NUMBER '0'
#define WORD '1'
#define ADDRSUFX '\''
#define NOTFOUND -1
#define MAXVAL 100
#define BUFSIZE 100
int apply(char[]);
double lookup(char[]);
double assign(double, int);
int getop(char[]);
void push(double);
double pop(void);
void peek(void);
void duplicate(void);
void swap(void);
void clear(void);
int sp = 0;
double val[MAXVAL];
double vars[26];
double recent = 0.0;
int getch(void);
char buff;
int havebuff = 0;
int main(void)
{
int i, type;
double op2;
char s[MAXOP];
for (i = 0; i < 26; i++)
vars[i] = 0.0;
while ((type = getop(s)) != EOF) {
switch (type) {
case NUMBER:
push(atof(s));
break;
case WORD:
if (apply(s))
;
else
push(lookup(s));
break;
case '@':
op2 = pop();
push(assign(pop(), op2));
break;
case '+':
push(pop() + pop());
break;
case '*':
push(pop() * pop());
break;
case '-':
op2 = pop();
push(pop() - op2);
break;
case '/':
op2 = pop();
if (op2 != 0.0)
push(pop() / op2);
else
printf("error: zero divisor\n");
break;
case '%':
op2 = pop();
if (op2 != 0.0)
push((long)pop() % (long)op2);
else
printf("error: zero divisor (mod)\n");
break;
case '?':
peek();
break;
case '"':
duplicate();
break;
case '~':
swap();
break;
case '`':
clear();
break;
case '$':
push(recent);
break;
case '\n':
printf("\t%.8g\n", recent = pop());
break;
default:
printf("error: unknown command %s\n", s);
break;
}
}
return 0;
}
int apply(char word[])
{
double op2;
if (strcmp(word, "sin") == 0) {
push(sin(pop()));
} else if (strcmp(word, "cos") == 0) {
push(cos(pop()));
} else if (strcmp(word, "tan") == 0) {
push(tan(pop()));
} else if (strcmp(word, "asin") == 0) {
push(asin(pop()));
} else if (strcmp(word, "acos") == 0) {
push(acos(pop()));
} else if (strcmp(word, "atan") == 0) {
push(atan(pop()));
} else if (strcmp(word, "atan2") == 0) {
op2 = pop();
push(atan2(pop(), op2));
} else if (strcmp(word, "exp") == 0) {
push(exp(pop()));
} else if (strcmp(word, "log") == 0) {
push(log(pop()));
} else if (strcmp(word, "pow") == 0) {
op2 = pop();
push(pow(pop(), op2));
} else if (strcmp(word, "sqrt") == 0) {
push(sqrt(pop()));
} else if (strcmp(word, "ceil") == 0) {
push(ceil(pop()));
} else if (strcmp(word, "floor") == 0) {
push(floor(pop()));
} else {
return 0;
}
return 1;
}
double lookup(char word[])
{
char c;
if (islower(c = word[0])) {
if (word[1] == ADDRSUFX)
return c - 'a';
else
return vars[c - 'a'];
}
printf("error: undefined %s\n", word);
return 0.0;
}
double assign(double val, int addr)
{
if (0 <= addr && addr <= 26)
return vars[addr] = val;
printf("error: invalid address %d\n", addr);
return 0.0;
}
void push(double f)
{
if (sp < MAXVAL)
val[sp++] = f;
else
printf("error: stack full, can't push %g\n", f);
}
double pop(void)
{
if (sp > 0)
return val[--sp];
else {
printf("error: stack empty\n");
return 0.0;
}
}
void peek(void)
{
if (sp > 0)
printf("peek: %g\n", val[sp - 1]);
else
printf("error: stack empty\n");
}
void duplicate(void)
{
if (sp <= 0)
printf("error: stack empty\n");
else if (sp >= MAXVAL)
printf("error: stack full, can't duplicate\n");
else
push(val[sp - 1]);
}
void swap(void)
{
int t;
if (sp <= 1) {
printf("error: stack has fewer than two items\n");
} else {
t = val[sp - 2];
val[sp - 2] = val[sp - 1];
val[sp - 1] = t;
}
}
void clear(void)
{
sp = 0;
}
int getop(char s[])
{
int i = 0;
static int c, gotc = 0;
s[0] = gotc ? c : (c = getch());
gotc = 0;
while (c == ' ' || c == '\t')
s[0] = c = getch();
if (isalpha(c)) {
while (isalnum(s[++i] = c = getch()))
;
if (c == ADDRSUFX)
s[i + 1] = '\0';
else {
s[i] = '\0';
if (c != EOF)
gotc = 1;
}
return WORD;
}
s[1] = '\0';
if (!isdigit(c) && c != '.' && c != '-')
return c;
if (c == '-') {
c = getch();
if (!isdigit(c) && c != '.')
return '-';
s[++i] = c;
}
if (isdigit(c))
while (isdigit(s[++i] = c = getch()))
;
if (c == '.')
while (isdigit(s[++i] = c = getch()))
;
s[i] = '\0';
if (c != EOF)
gotc = 1;
return NUMBER;
}
int getch(void)
{
if (havebuff) {
havebuff = 0;
return buff;
} else {
return getchar();
}
}
|
the_stack_data/173578327.c | /*
URI Online Judge | 2235
Walking in Time
By Maratona de Programação SBC BR Brazil
https://www.urionlinejudge.com.br/judge/en/problems/view/2235
Timelimit: 1
Imagine you have a time machine that can be used up to three times, and every use of the machine you can choose to go back to the past or go to the future. The machine has three fixed loans; each credit represents a certain number of years, and can be used to get this amount of years for the past or for the future. You can make one, two or three trips, and each of these three credits can only be used once. For example, if the credits are 5, 12 and 9, you could decide to make two trips: go five years into the future and then go back nine years to the past. This way, you end four years in the past, in 2012. It could also make three trips, all going to the future, using the credits in any order, ending in 2042.
In this problem, given the values of the three machine credits, your program should say if is possible or not travel back in time and return to the present, making at least one trip and at most three trips; always using each of the three credit at most once.
Input
The input consists of a single line containing three credits A, B e C (1 ≤ A, B, C ≤ 1000).
Output
Your program should print a line containing the character 'S' if it possible travel in time and back to present, or 'N' if it's not possible.
@author Marcos Lima
@profile https://www.urionlinejudge.com.br/judge/pt/profile/242402
@status Accepted
@language C (gcc 4.8.5, -O2 -lm) [+0s]
@time 0.000s
@size 443 Bytes
@submission 1/27/20, 8:39:26 AM
*/
#include <stdio.h>
int main()
{
char i,j,k;
short n[3];
scanf("%hd %hd %hd", &n[0], &n[1], &n[2]);
for (i=-1; i<2; i++)
for (j=-1; j<2; j++)
for (k=-1; k<2; k++) {
if ((i == 0) && (j == 0) && (k == 0)) {
continue;
} else if ((i*n[0])+(j*n[1])+(k*n[2]) == 0) {
printf("S\n");
return 0;
}
}
printf("N\n");
return 0;
} |
the_stack_data/104950.c | #include <stdio.h>
char opposite_char(char);
int main()
{
char c;
scanf("%c", &c);
printf("%c\n", opposite_char(c));
return 0;
}
char opposite_char(char c)
{
if((c >= 'a') && (c <= 'z'))
{
int middle = ('a' +(('z' - 'a')/2));
char opposite = middle - c + middle + 1;
return opposite;
}
if((c >= 'A') && (c <= 'Z'))
{
int middle = ('A' +(('Z' - 'A')/2));
char opposite = middle - c + middle + 1;
return opposite;
}
return 0;
}
|
the_stack_data/107954014.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static doublecomplex c_b2 = {0.,0.};
static integer c__1 = 1;
/* > \brief \b ZHPTRD */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download ZHPTRD + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhptrd.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhptrd.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhptrd.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE ZHPTRD( UPLO, N, AP, D, E, TAU, INFO ) */
/* CHARACTER UPLO */
/* INTEGER INFO, N */
/* DOUBLE PRECISION D( * ), E( * ) */
/* COMPLEX*16 AP( * ), TAU( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > ZHPTRD reduces a complex Hermitian matrix A stored in packed form to */
/* > real symmetric tridiagonal form T by a unitary similarity */
/* > transformation: Q**H * A * Q = T. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] UPLO */
/* > \verbatim */
/* > UPLO is CHARACTER*1 */
/* > = 'U': Upper triangle of A is stored; */
/* > = 'L': Lower triangle of A is stored. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix A. N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in,out] AP */
/* > \verbatim */
/* > AP is COMPLEX*16 array, dimension (N*(N+1)/2) */
/* > On entry, the upper or lower triangle of the Hermitian matrix */
/* > A, packed columnwise in a linear array. The j-th column of A */
/* > is stored in the array AP as follows: */
/* > if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
/* > if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
/* > On exit, if UPLO = 'U', the diagonal and first superdiagonal */
/* > of A are overwritten by the corresponding elements of the */
/* > tridiagonal matrix T, and the elements above the first */
/* > superdiagonal, with the array TAU, represent the unitary */
/* > matrix Q as a product of elementary reflectors; if UPLO */
/* > = 'L', the diagonal and first subdiagonal of A are over- */
/* > written by the corresponding elements of the tridiagonal */
/* > matrix T, and the elements below the first subdiagonal, with */
/* > the array TAU, represent the unitary matrix Q as a product */
/* > of elementary reflectors. See Further Details. */
/* > \endverbatim */
/* > */
/* > \param[out] D */
/* > \verbatim */
/* > D is DOUBLE PRECISION array, dimension (N) */
/* > The diagonal elements of the tridiagonal matrix T: */
/* > D(i) = A(i,i). */
/* > \endverbatim */
/* > */
/* > \param[out] E */
/* > \verbatim */
/* > E is DOUBLE PRECISION array, dimension (N-1) */
/* > The off-diagonal elements of the tridiagonal matrix T: */
/* > E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
/* > \endverbatim */
/* > */
/* > \param[out] TAU */
/* > \verbatim */
/* > TAU is COMPLEX*16 array, dimension (N-1) */
/* > The scalar factors of the elementary reflectors (see Further */
/* > Details). */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup complex16OTHERcomputational */
/* > \par Further Details: */
/* ===================== */
/* > */
/* > \verbatim */
/* > */
/* > If UPLO = 'U', the matrix Q is represented as a product of elementary */
/* > reflectors */
/* > */
/* > Q = H(n-1) . . . H(2) H(1). */
/* > */
/* > Each H(i) has the form */
/* > */
/* > H(i) = I - tau * v * v**H */
/* > */
/* > where tau is a complex scalar, and v is a complex vector with */
/* > v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP, */
/* > overwriting A(1:i-1,i+1), and tau is stored in TAU(i). */
/* > */
/* > If UPLO = 'L', the matrix Q is represented as a product of elementary */
/* > reflectors */
/* > */
/* > Q = H(1) H(2) . . . H(n-1). */
/* > */
/* > Each H(i) has the form */
/* > */
/* > H(i) = I - tau * v * v**H */
/* > */
/* > where tau is a complex scalar, and v is a complex vector with */
/* > v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP, */
/* > overwriting A(i+2:n,i), and tau is stored in TAU(i). */
/* > \endverbatim */
/* > */
/* ===================================================================== */
/* Subroutine */ int zhptrd_(char *uplo, integer *n, doublecomplex *ap,
doublereal *d__, doublereal *e, doublecomplex *tau, integer *info)
{
/* System generated locals */
integer i__1, i__2, i__3;
doublereal d__1;
doublecomplex z__1, z__2, z__3, z__4;
/* Local variables */
doublecomplex taui;
extern /* Subroutine */ int zhpr2_(char *, integer *, doublecomplex *,
doublecomplex *, integer *, doublecomplex *, integer *,
doublecomplex *);
integer i__;
doublecomplex alpha;
extern logical lsame_(char *, char *);
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
doublecomplex *, integer *, doublecomplex *, integer *);
integer i1;
logical upper;
extern /* Subroutine */ int zhpmv_(char *, integer *, doublecomplex *,
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
doublecomplex *, integer *), zaxpy_(integer *,
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
integer *);
integer ii;
extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zlarfg_(
integer *, doublecomplex *, doublecomplex *, integer *,
doublecomplex *);
integer i1i1;
/* -- LAPACK computational routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ===================================================================== */
/* Test the input parameters */
/* Parameter adjustments */
--tau;
--e;
--d__;
--ap;
/* Function Body */
*info = 0;
upper = lsame_(uplo, "U");
if (! upper && ! lsame_(uplo, "L")) {
*info = -1;
} else if (*n < 0) {
*info = -2;
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("ZHPTRD", &i__1, (ftnlen)6);
return 0;
}
/* Quick return if possible */
if (*n <= 0) {
return 0;
}
if (upper) {
/* Reduce the upper triangle of A. */
/* I1 is the index in AP of A(1,I+1). */
i1 = *n * (*n - 1) / 2 + 1;
i__1 = i1 + *n - 1;
i__2 = i1 + *n - 1;
d__1 = ap[i__2].r;
ap[i__1].r = d__1, ap[i__1].i = 0.;
for (i__ = *n - 1; i__ >= 1; --i__) {
/* Generate elementary reflector H(i) = I - tau * v * v**H */
/* to annihilate A(1:i-1,i+1) */
i__1 = i1 + i__ - 1;
alpha.r = ap[i__1].r, alpha.i = ap[i__1].i;
zlarfg_(&i__, &alpha, &ap[i1], &c__1, &taui);
i__1 = i__;
e[i__1] = alpha.r;
if (taui.r != 0. || taui.i != 0.) {
/* Apply H(i) from both sides to A(1:i,1:i) */
i__1 = i1 + i__ - 1;
ap[i__1].r = 1., ap[i__1].i = 0.;
/* Compute y := tau * A * v storing y in TAU(1:i) */
zhpmv_(uplo, &i__, &taui, &ap[1], &ap[i1], &c__1, &c_b2, &tau[
1], &c__1);
/* Compute w := y - 1/2 * tau * (y**H *v) * v */
z__3.r = -.5, z__3.i = 0.;
z__2.r = z__3.r * taui.r - z__3.i * taui.i, z__2.i = z__3.r *
taui.i + z__3.i * taui.r;
zdotc_(&z__4, &i__, &tau[1], &c__1, &ap[i1], &c__1);
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r *
z__4.i + z__2.i * z__4.r;
alpha.r = z__1.r, alpha.i = z__1.i;
zaxpy_(&i__, &alpha, &ap[i1], &c__1, &tau[1], &c__1);
/* Apply the transformation as a rank-2 update: */
/* A := A - v * w**H - w * v**H */
z__1.r = -1., z__1.i = 0.;
zhpr2_(uplo, &i__, &z__1, &ap[i1], &c__1, &tau[1], &c__1, &ap[
1]);
}
i__1 = i1 + i__ - 1;
i__2 = i__;
ap[i__1].r = e[i__2], ap[i__1].i = 0.;
i__1 = i__ + 1;
i__2 = i1 + i__;
d__[i__1] = ap[i__2].r;
i__1 = i__;
tau[i__1].r = taui.r, tau[i__1].i = taui.i;
i1 -= i__;
/* L10: */
}
d__[1] = ap[1].r;
} else {
/* Reduce the lower triangle of A. II is the index in AP of */
/* A(i,i) and I1I1 is the index of A(i+1,i+1). */
ii = 1;
d__1 = ap[1].r;
ap[1].r = d__1, ap[1].i = 0.;
i__1 = *n - 1;
for (i__ = 1; i__ <= i__1; ++i__) {
i1i1 = ii + *n - i__ + 1;
/* Generate elementary reflector H(i) = I - tau * v * v**H */
/* to annihilate A(i+2:n,i) */
i__2 = ii + 1;
alpha.r = ap[i__2].r, alpha.i = ap[i__2].i;
i__2 = *n - i__;
zlarfg_(&i__2, &alpha, &ap[ii + 2], &c__1, &taui);
i__2 = i__;
e[i__2] = alpha.r;
if (taui.r != 0. || taui.i != 0.) {
/* Apply H(i) from both sides to A(i+1:n,i+1:n) */
i__2 = ii + 1;
ap[i__2].r = 1., ap[i__2].i = 0.;
/* Compute y := tau * A * v storing y in TAU(i:n-1) */
i__2 = *n - i__;
zhpmv_(uplo, &i__2, &taui, &ap[i1i1], &ap[ii + 1], &c__1, &
c_b2, &tau[i__], &c__1);
/* Compute w := y - 1/2 * tau * (y**H *v) * v */
z__3.r = -.5, z__3.i = 0.;
z__2.r = z__3.r * taui.r - z__3.i * taui.i, z__2.i = z__3.r *
taui.i + z__3.i * taui.r;
i__2 = *n - i__;
zdotc_(&z__4, &i__2, &tau[i__], &c__1, &ap[ii + 1], &c__1);
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r *
z__4.i + z__2.i * z__4.r;
alpha.r = z__1.r, alpha.i = z__1.i;
i__2 = *n - i__;
zaxpy_(&i__2, &alpha, &ap[ii + 1], &c__1, &tau[i__], &c__1);
/* Apply the transformation as a rank-2 update: */
/* A := A - v * w**H - w * v**H */
i__2 = *n - i__;
z__1.r = -1., z__1.i = 0.;
zhpr2_(uplo, &i__2, &z__1, &ap[ii + 1], &c__1, &tau[i__], &
c__1, &ap[i1i1]);
}
i__2 = ii + 1;
i__3 = i__;
ap[i__2].r = e[i__3], ap[i__2].i = 0.;
i__2 = i__;
i__3 = ii;
d__[i__2] = ap[i__3].r;
i__2 = i__;
tau[i__2].r = taui.r, tau[i__2].i = taui.i;
ii = i1i1;
/* L20: */
}
i__1 = *n;
i__2 = ii;
d__[i__1] = ap[i__2].r;
}
return 0;
/* End of ZHPTRD */
} /* zhptrd_ */
|
the_stack_data/117327131.c | #include <stdio.h>
#include <stdlib.h>
/*
*
*/
void printArray (int *arr, int size) {
int i;
if (arr != NULL) {
for (i = 0; i < size; i++) {
// Print each element out
printf("%d ", *(arr + i));
//Print addresses of each element printf ("%p", (arr + i));
//Printing a new line printf ("\n");
}
}
}
int main() {
// Allows user to specify the original array size, stored in variable n1.
printf ("Enter original array size: ");
int n1 = 0;
scanf("%d", &n1);
//a- Create a new array *a1 of n1 ints using malloc
int *a1 = malloc (n1 * sizeof (int));
//b- Remove comments for if statement below //b- Set each element in a1 to 100 + indexValue ??
if (a1 == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
int index;
for (index = 0; index < n1; index++) {
a1[index] = 100 + index;
}
printf("Printing the First array allocated using malloc\n");
//c- Print each element and addresses out (to make sure things look right)
printArray (a1, n1);
// User specifies the new array size, stored in variable n2.
printf ("\nEnter new array size: ");
int n2 = 0;
scanf("%d", &n2);
// Task 2
//d- Dynamically change the array a1 to size n2
a1 = realloc(a1,n2 * sizeof(int));
//e- Remove comments for if statement below
if (a1 == NULL){
printf("Error! memory not allocated.");
exit(0);
}
//e- If the new array is a larger size, set all new members to 200 + indexValue.
if (n2 > n1){
int index;
for (index = n1; index < n2; index++) {
a1[index] = 200 + index;
}
}
printf("Printing the reallocated array: \n");
//f- Print each element and addresses out (to make sure things look right)
printArray(a1, n2);
//g-Free the allocated memory for a1
free (a1);
//added below line to set a1 = NULL
a1 = NULL;
printf("\nEnter new array size to be initialized with 0: ");
int n3 = 0;
scanf("%d", &n3);
//h- Remove comments for if statement
//h- Using calloc create a new array and assign it to a2 //with new array size, stored in variable n3.
int *a2 = (int*) calloc(n3, sizeof(int));
if (a2 == NULL) {
printf("Error! memory not allocated.");
exit(0);
}
printf("Printing the array created using calloc: \n");
//i- Print array a2 with size n3
printArray(a2, n3);
//j- Print array a1 again, How you can x this problem
/* free(a1) does not mean memory can't be accessed. System is free to use the memory. In C, we have to be careful before accessing such pointers
To fix the above problem, you need to add NULL check into printArray function and after free(a1), set a1=NULL
*/
printf("Printing deallocated array a1: \n");
printArray(a1, n2);
// Done with arrays now, free the allocated memory and assign NULL
free (a2);
a1 = NULL;
a2 = NULL;
printf("Program Successfully Completed!");
}
|
the_stack_data/165767406.c | #include "stdio.h"
#include "stdlib.h"
int main(int argc, char **argv) {
printf("%d\n", foo(atoi(argv[1])));
float c = 5;
float b=c+2;
return 0;
}
|
the_stack_data/878046.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamaurai <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/30 12:00:52 by mamaurai #+# #+# */
/* Updated: 2021/06/30 12:00:54 by mamaurai ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
|
the_stack_data/725968.c | #include <stdio.h>
#include <stdlib.h>
int main() {
double val = strtod("-20.23 hello world", NULL);
printf("val: %lf\n", val);
val = strtod("+20.23 hello world", NULL);
printf("val: %lf\n", val);
return 0;
}
|
the_stack_data/991575.c | /*
Mike Zrimsek
Systems Programming
Homework 1 - Who
*/
#include <stdio.h>
#include <sys/types.h>
#include <utmp.h>
#include <fcntl.h>
#include <time.h>
#define SHOWHOST
void show_info(struct utmp *);
void showtime(time_t);
int main()
{
struct utmp *utbufp,
*utmp_next();
if ( utmp_open( UTMP_FILE ) == -1 ){
perror(UTMP_FILE);
exit(1);
}
while ( ( utbufp = utmp_next() ) != ((struct utmp *) NULL) ){
show_info( utbufp );
}
utmp_close( );
return 0;
}
void show_info( struct utmp *utbufp ){
printf("%-8.8s", utbufp->ut_name);
printf(" ");
printf("%-8.8s", utbufp->ut_line);
printf(" ");
showtime( utbufp->ut_time );
#ifdef SHOWHOST
if ( utbufp->ut_host[0] != '\0' ){
printf(" (%s)", utbufp->ut_host);
}
#endif
printf("\n");
}
void showtime( time_t timeval ){
char *ctime();
char *cp;
cp = ctime( &timeval );
printf("%12.12s", cp+4 );
}
|
the_stack_data/90765880.c | /****************/
/* Others games */
/****************/
//arkanoid extern struct GameDriver driver_arkbloc2;
//atarisy2 extern struct GameDriver driver_csprint;
//cps1 extern struct GameDriver driver_ghoulsj;
//cps1 extern struct GameDriver driver_mtwins;
//cps1 extern struct GameDriver driver_pang3;
//cps1 extern struct GameDriver driver_pang3j;
//cps1 extern struct GameDriver driver_pnickj;
//cps1 extern struct GameDriver driver_punishrj;
//cps1 extern struct GameDriver driver_punishru;
//cps1 extern struct GameDriver driver_punisher;
//cps1 extern struct GameDriver driver_wofa;
//cps1 extern struct GameDriver driver_slammast;
//cps1 extern struct GameDriver driver_mercsj;
//atarisy2 extern struct GameDriver driver_ssprint;
//extern struct GameDriver driver_tetrist;
//cps1 extern struct GameDriver driver_wof;
extern struct GameDriver driver_99lstwra;
extern struct GameDriver driver_99lstwar;
extern struct GameDriver driver_aso;
extern struct GameDriver driver_hatena;
extern struct GameDriver driver_aerofgtb;
extern struct GameDriver driver_aerofgtc;
extern struct GameDriver driver_aerofgt;
extern struct GameDriver driver_aeroboto;
extern struct GameDriver driver_koshien;
extern struct GameDriver driver_airbustr;
extern struct GameDriver driver_airwolf;
extern struct GameDriver driver_alcon;
extern struct GameDriver driver_alpine;
extern struct GameDriver driver_alpinea;
extern struct GameDriver driver_ambush;
extern struct GameDriver driver_horshoes;
extern struct GameDriver driver_appoooh;
extern struct GameDriver driver_arabiana;
extern struct GameDriver driver_arabian;
extern struct GameDriver driver_arbalest;
extern struct GameDriver driver_argus;
extern struct GameDriver driver_arkarea;
extern struct GameDriver driver_armwrest;
extern struct GameDriver driver_armedf;
extern struct GameDriver driver_ashura;
extern struct GameDriver driver_ashurau;
extern struct GameDriver driver_athena;
extern struct GameDriver driver_baluba;
extern struct GameDriver driver_bankp;
extern struct GameDriver driver_btlfield;
extern struct GameDriver driver_battlane;
extern struct GameDriver driver_battlan2;
extern struct GameDriver driver_battlan3;
extern struct GameDriver driver_berlwall;
extern struct GameDriver driver_berlwalt;
extern struct GameDriver driver_bermudaj;
extern struct GameDriver driver_bermudaa;
extern struct GameDriver driver_bermudat;
extern struct GameDriver driver_berzerk;
extern struct GameDriver driver_berzerk1;
extern struct GameDriver driver_bigkarnk;
extern struct GameDriver driver_bigprowr;
extern struct GameDriver driver_bioatack;
extern struct GameDriver driver_biomtoy;
extern struct GameDriver driver_bking2;
extern struct GameDriver driver_blandia;
extern struct GameDriver driver_blasto;
extern struct GameDriver driver_blockade;
extern struct GameDriver driver_blocken;
extern struct GameDriver driver_bloodbro;
extern struct GameDriver driver_blueprnj;
extern struct GameDriver driver_blueprnt;
extern struct GameDriver driver_boblbobl;
extern struct GameDriver driver_bogeyman;
extern struct GameDriver driver_bjtwin;
extern struct GameDriver driver_bowlrama;
extern struct GameDriver driver_bublbobr;
extern struct GameDriver driver_bubbobr1;
extern struct GameDriver driver_bublbobl;
extern struct GameDriver driver_butasan;
extern struct GameDriver driver_cachat;
extern struct GameDriver driver_calibr50;
extern struct GameDriver driver_cameltry;
extern struct GameDriver driver_cameltru;
extern struct GameDriver driver_challeng;
extern struct GameDriver driver_champbbj;
extern struct GameDriver driver_champbb2;
extern struct GameDriver driver_champbas;
extern struct GameDriver driver_champwrj;
extern struct GameDriver driver_champwru;
extern struct GameDriver driver_champwr;
extern struct GameDriver driver_cheyenne;
extern struct GameDriver driver_cshift;
extern struct GameDriver driver_chiller;
extern struct GameDriver driver_chopper;
extern struct GameDriver driver_circus;
extern struct GameDriver driver_claypign;
extern struct GameDriver driver_combat;
extern struct GameDriver driver_comotion;
extern struct GameDriver driver_clbowl;
extern struct GameDriver driver_cop01;
extern struct GameDriver driver_cop01a;
extern struct GameDriver driver_cracksht;
extern struct GameDriver driver_crash;
extern struct GameDriver driver_crbaloon;
extern struct GameDriver driver_crbalon2;
extern struct GameDriver driver_crazyblk;
extern struct GameDriver driver_cclimbr2;
extern struct GameDriver driver_crimecj;
extern struct GameDriver driver_crimecu;
extern struct GameDriver driver_crimec;
extern struct GameDriver driver_crossbow;
extern struct GameDriver driver_cubybop;
extern struct GameDriver driver_curvebal;
extern struct GameDriver driver_dcon;
extern struct GameDriver driver_ddayc;
extern struct GameDriver driver_dday;
extern struct GameDriver driver_dangar;
extern struct GameDriver driver_dangar2;
extern struct GameDriver driver_dangarb;
extern struct GameDriver driver_powj;
extern struct GameDriver driver_deadconj;
extern struct GameDriver driver_deadconx;
extern struct GameDriver driver_dinorexj;
extern struct GameDriver driver_dinorexu;
extern struct GameDriver driver_dinorex;
extern struct GameDriver driver_dogfight;
extern struct GameDriver driver_dogosoke;
extern struct GameDriver driver_dondokod;
extern struct GameDriver driver_dotrikun;
extern struct GameDriver driver_dotriku2;
extern struct GameDriver driver_dbldyn;
extern struct GameDriver driver_downtown;
extern struct GameDriver driver_drgnunit;
extern struct GameDriver driver_driftout;
extern struct GameDriver driver_driveout;
extern struct GameDriver driver_dynduke;
extern struct GameDriver driver_eggs;
extern struct GameDriver driver_elecyoyo;
extern struct GameDriver driver_elecyoy2;
extern struct GameDriver driver_elevatob;
extern struct GameDriver driver_elevator;
extern struct GameDriver driver_empcityj;
extern struct GameDriver driver_empcity;
extern struct GameDriver driver_euroch92;
extern struct GameDriver driver_wc90b;
extern struct GameDriver driver_excthour;
extern struct GameDriver driver_exctscca;
extern struct GameDriver driver_exctsccb;
extern struct GameDriver driver_exctscc2;
extern struct GameDriver driver_exctsccr;
extern struct GameDriver driver_exerizrb;
extern struct GameDriver driver_f1dreamb;
extern struct GameDriver driver_f1dream;
extern struct GameDriver driver_flstory;
extern struct GameDriver driver_flstoryj;
extern struct GameDriver driver_fantasyj;
extern struct GameDriver driver_fantasy;
extern struct GameDriver driver_sqbert;
extern struct GameDriver driver_fax;
extern struct GameDriver driver_fitegolf;
extern struct GameDriver driver_fhawk;
extern struct GameDriver driver_ftsoccer;
extern struct GameDriver driver_finalbj;
extern struct GameDriver driver_finalb;
extern struct GameDriver driver_fireone;
extern struct GameDriver driver_fitter;
extern struct GameDriver driver_flashgal;
extern struct GameDriver driver_footchmp;
extern struct GameDriver driver_formatz;
extern struct GameDriver driver_frenzy;
extern struct GameDriver driver_friskyt;
extern struct GameDriver driver_frontlin;
extern struct GameDriver driver_funkybee;
extern struct GameDriver driver_fnkyfish;
extern struct GameDriver driver_suprmou2;
extern struct GameDriver driver_galivan2;
extern struct GameDriver driver_galivan;
extern struct GameDriver driver_galpanic;
extern struct GameDriver driver_gangwars;
extern struct GameDriver driver_gangwarb;
extern struct GameDriver driver_gensitou;
extern struct GameDriver driver_getstarj;
extern struct GameDriver driver_getstarb;
extern struct GameDriver driver_gimeabrk;
extern struct GameDriver driver_ginganin;
extern struct GameDriver driver_gladiatr;
extern struct GameDriver driver_yamagchi;
extern struct GameDriver driver_gghost;
extern struct GameDriver driver_goindol;
extern struct GameDriver driver_goldmedl;
extern struct GameDriver driver_gotya;
extern struct GameDriver driver_gtmre;
extern struct GameDriver driver_gtmr;
extern struct GameDriver driver_gsword;
extern struct GameDriver driver_gridiron;
extern struct GameDriver driver_growlu;
extern struct GameDriver driver_growl;
extern struct GameDriver driver_getstar;
extern struct GameDriver driver_gwar;
extern struct GameDriver driver_gwara;
extern struct GameDriver driver_gwarb;
extern struct GameDriver driver_gwarj;
extern struct GameDriver driver_gunfront;
extern struct GameDriver driver_gunbird;
extern struct GameDriver driver_gundealr;
extern struct GameDriver driver_gundeala;
extern struct GameDriver driver_gunfronj;
extern struct GameDriver driver_gyrodine;
extern struct GameDriver driver_hal21j;
extern struct GameDriver driver_hal21;
extern struct GameDriver driver_hanaawas;
extern struct GameDriver driver_hardhat;
extern struct GameDriver driver_hardhead;
extern struct GameDriver driver_hardhedb;
extern struct GameDriver driver_hthero;
extern struct GameDriver driver_hattrick;
extern struct GameDriver driver_hatris;
extern struct GameDriver driver_heberpop;
extern struct GameDriver driver_hexa;
extern struct GameDriver driver_hwrace;
extern struct GameDriver driver_hitnmis2;
extern struct GameDriver driver_hitnmiss;
extern struct GameDriver driver_hitice;
extern struct GameDriver driver_homo;
extern struct GameDriver driver_hustle;
extern struct GameDriver driver_ikari3;
extern struct GameDriver driver_ikarijpb;
extern struct GameDriver driver_ikarijp;
extern struct GameDriver driver_ikari;
extern struct GameDriver driver_insector;
extern struct GameDriver driver_intrepid;
extern struct GameDriver driver_intrepi2;
extern struct GameDriver driver_jackrabt;
extern struct GameDriver driver_jackrab2;
extern struct GameDriver driver_jackrabs;
extern struct GameDriver driver_joyfulr;
extern struct GameDriver driver_jungleh;
extern struct GameDriver driver_junglek;
extern struct GameDriver driver_junglkj2;
extern struct GameDriver driver_kangaroa;
extern struct GameDriver driver_kangarob;
extern struct GameDriver driver_kangaroo;
extern struct GameDriver driver_kaos;
extern struct GameDriver driver_karatblu;
extern struct GameDriver driver_karatblz;
extern struct GameDriver driver_karianx;
extern struct GameDriver driver_kikstart;
extern struct GameDriver driver_killcom;
extern struct GameDriver driver_kncljoe;
extern struct GameDriver driver_kncljoea;
extern struct GameDriver driver_kodure;
extern struct GameDriver driver_legofair;
extern struct GameDriver driver_kram;
extern struct GameDriver driver_kram2;
extern struct GameDriver driver_krull;
extern struct GameDriver driver_kurikint;
extern struct GameDriver driver_kurikina;
extern struct GameDriver driver_kyros;
extern struct GameDriver driver_lsasquad;
extern struct GameDriver driver_lasso;
extern struct GameDriver driver_ledstorm;
extern struct GameDriver driver_lkageb;
extern struct GameDriver driver_lkageb2;
extern struct GameDriver driver_lkageb3;
extern struct GameDriver driver_lkage;
extern struct GameDriver driver_leprechn;
extern struct GameDriver driver_liquidku;
extern struct GameDriver driver_liquidk;
extern struct GameDriver driver_logicpro;
extern struct GameDriver driver_logicpr2;
extern struct GameDriver driver_mach3;
extern struct GameDriver driver_m79amb;
extern struct GameDriver driver_machomou;
extern struct GameDriver driver_madcrash;
extern struct GameDriver driver_mplanets;
extern struct GameDriver driver_magix;
extern struct GameDriver driver_mgakuen2;
extern struct GameDriver driver_mgakuen;
extern struct GameDriver driver_mjnquest;
extern struct GameDriver driver_mjnquesb;
extern struct GameDriver driver_majest12;
extern struct GameDriver driver_maniach;
extern struct GameDriver driver_maniach2;
extern struct GameDriver driver_marvins;
extern struct GameDriver driver_masterw;
extern struct GameDriver driver_matmania;
extern struct GameDriver driver_megaforc;
extern struct GameDriver driver_megaznik;
extern struct GameDriver driver_megatack;
extern struct GameDriver driver_mermaid;
extern struct GameDriver driver_metafox;
extern struct GameDriver driver_minigolf;
extern struct GameDriver driver_minigol2;
extern struct GameDriver driver_minivadr;
extern struct GameDriver driver_mizubaku;
extern struct GameDriver driver_moguchan;
extern struct GameDriver driver_mole;
extern struct GameDriver driver_momoko;
extern struct GameDriver driver_monymony;
extern struct GameDriver driver_mtrap3;
extern struct GameDriver driver_mtrap4;
extern struct GameDriver driver_mtrap;
extern struct GameDriver driver_mrjong;
extern struct GameDriver driver_mnchmobl;
extern struct GameDriver driver_mnight;
extern struct GameDriver driver_mystston;
extern struct GameDriver driver_nametune;
extern struct GameDriver driver_nastar;
extern struct GameDriver driver_nastarw;
extern struct GameDriver driver_nibbler;
extern struct GameDriver driver_nibblera;
extern struct GameDriver driver_nstocker;
extern struct GameDriver driver_ninjemak;
extern struct GameDriver driver_gaiden;
extern struct GameDriver driver_ninjakd2;
extern struct GameDriver driver_ninjak2a;
extern struct GameDriver driver_ninjak2b;
extern struct GameDriver driver_ninjakj;
extern struct GameDriver driver_ninjak;
extern struct GameDriver driver_ryukendn;
extern struct GameDriver driver_nunchaku;
extern struct GameDriver driver_otwalls;
extern struct GameDriver driver_ohmygod;
extern struct GameDriver driver_ogonsiro;
extern struct GameDriver driver_pow;
extern struct GameDriver driver_palamed;
extern struct GameDriver driver_pang;
extern struct GameDriver driver_pangb;
extern struct GameDriver driver_pepper2;
extern struct GameDriver driver_percuss;
extern struct GameDriver driver_pbaction;
extern struct GameDriver driver_pbactio2;
extern struct GameDriver driver_pinbos;
extern struct GameDriver driver_pinbo;
extern struct GameDriver driver_pballoon;
extern struct GameDriver driver_pipedrm;
extern struct GameDriver driver_thepit;
extern struct GameDriver driver_plgirls;
extern struct GameDriver driver_plgirls2;
extern struct GameDriver driver_plotting;
extern struct GameDriver driver_pkladies;
extern struct GameDriver driver_polyplay;
extern struct GameDriver driver_pompingw;
extern struct GameDriver driver_portman;
extern struct GameDriver driver_potogold;
extern struct GameDriver driver_powerins;
extern struct GameDriver driver_pspikes;
extern struct GameDriver driver_prehislu;
extern struct GameDriver driver_prehisle;
extern struct GameDriver driver_psychic5;
extern struct GameDriver driver_psychosj;
extern struct GameDriver driver_psychos;
extern struct GameDriver driver_pulirulj;
extern struct GameDriver driver_pulirula;
extern struct GameDriver driver_punchout;
extern struct GameDriver driver_puzbobb;
extern struct GameDriver driver_puzznic;
extern struct GameDriver driver_qbertjp;
extern struct GameDriver driver_qbert;
extern struct GameDriver driver_qbertqub;
extern struct GameDriver driver_qix;
extern struct GameDriver driver_qixa;
extern struct GameDriver driver_qixb;
extern struct GameDriver driver_qix2;
extern struct GameDriver driver_qzchikyu;
extern struct GameDriver driver_qcrayon;
extern struct GameDriver driver_qcrayon2;
extern struct GameDriver driver_quizhq;
extern struct GameDriver driver_qjinsei;
extern struct GameDriver driver_qzquest;
extern struct GameDriver driver_qzshowby;
extern struct GameDriver driver_qtorimon;
extern struct GameDriver driver_rpunch;
extern struct GameDriver driver_rabiolep;
extern struct GameDriver driver_rdaction;
extern struct GameDriver driver_radrad;
extern struct GameDriver driver_raidena;
extern struct GameDriver driver_raidenk;
extern struct GameDriver driver_raiden;
extern struct GameDriver driver_raimais;
extern struct GameDriver driver_rambo3;
extern struct GameDriver driver_rambo3a;
extern struct GameDriver driver_rastsag2;
extern struct GameDriver driver_reactor;
extern struct GameDriver driver_repulse;
extern struct GameDriver driver_rescrdsa;
extern struct GameDriver driver_rescraid;
extern struct GameDriver driver_retofin1;
extern struct GameDriver driver_retofin2;
extern struct GameDriver driver_retofinv;
extern struct GameDriver driver_ripcord;
extern struct GameDriver driver_robotbwl;
extern struct GameDriver driver_rranger;
extern struct GameDriver driver_roundup;
extern struct GameDriver driver_route16b;
extern struct GameDriver driver_route16;
extern struct GameDriver driver_royalmah;
extern struct GameDriver driver_rugrats;
extern struct GameDriver driver_runark;
extern struct GameDriver driver_srdmissn;
extern struct GameDriver driver_sercharu;
extern struct GameDriver driver_searchar;
extern struct GameDriver driver_safarir;
extern struct GameDriver driver_tsamurai;
extern struct GameDriver driver_tsamura2;
extern struct GameDriver driver_sasuke;
extern struct GameDriver driver_satansat;
extern struct GameDriver driver_saturn;
extern struct GameDriver driver_sauro;
extern struct GameDriver driver_scionc;
extern struct GameDriver driver_scion;
extern struct GameDriver driver_scregg;
extern struct GameDriver driver_screwloo;
extern struct GameDriver driver_sfposeid;
extern struct GameDriver driver_sectrzon;
extern struct GameDriver driver_seicross;
extern struct GameDriver driver_sngkace;
extern struct GameDriver driver_senjyo;
extern struct GameDriver driver_sentetst;
extern struct GameDriver driver_shadoww;
extern struct GameDriver driver_shangha3;
extern struct GameDriver driver_shanghai;
extern struct GameDriver driver_sharkatt;
extern struct GameDriver driver_shisen;
extern struct GameDriver driver_showdown;
extern struct GameDriver driver_sichuana;
extern struct GameDriver driver_sichuan2;
extern struct GameDriver driver_sidetrac;
extern struct GameDriver driver_silentd;
extern struct GameDriver driver_skyadvnt;
extern struct GameDriver driver_skyfox;
extern struct GameDriver driver_skylancr;
extern struct GameDriver driver_skysoldr;
extern struct GameDriver driver_skywolf;
extern struct GameDriver driver_skywolf2;
extern struct GameDriver driver_slapbtuk;
extern struct GameDriver driver_slapbtjp;
extern struct GameDriver driver_slapfigh;
extern struct GameDriver driver_snakjack;
extern struct GameDriver driver_snakepit;
extern struct GameDriver driver_solarwar;
extern struct GameDriver driver_solfigtr;
extern struct GameDriver driver_sonofphx;
extern struct GameDriver driver_sonicwi;
extern struct GameDriver driver_sdungeon;
extern struct GameDriver driver_spacedx;
extern struct GameDriver driver_spaceskr;
extern struct GameDriver driver_stactics;
extern struct GameDriver driver_speakres;
extern struct GameDriver driver_spectar1;
extern struct GameDriver driver_spectar;
extern struct GameDriver driver_speedbal;
extern struct GameDriver driver_spiders;
extern struct GameDriver driver_spiders2;
extern struct GameDriver driver_spiker;
extern struct GameDriver driver_spinlbrj;
extern struct GameDriver driver_spinlbru;
extern struct GameDriver driver_spinlbrk;
extern struct GameDriver driver_splash;
extern struct GameDriver driver_starcrus;
extern struct GameDriver driver_starfire;
extern struct GameDriver driver_starfore;
extern struct GameDriver driver_starforc;
extern struct GameDriver driver_stinger;
extern struct GameDriver driver_stocker;
extern struct GameDriver driver_storming;
extern struct GameDriver driver_stratvxb;
extern struct GameDriver driver_stratvox;
extern struct GameDriver driver_stfight;
extern struct GameDriver driver_sfootbal;
extern struct GameDriver driver_streetsj;
extern struct GameDriver driver_streets1;
extern struct GameDriver driver_streetsm;
extern struct GameDriver driver_sboblbob;
extern struct GameDriver driver_sbbros;
extern struct GameDriver driver_sbasebal;
extern struct GameDriver driver_sformula;
extern struct GameDriver driver_marukin;
extern struct GameDriver driver_suprmous;
extern struct GameDriver driver_spang;
extern struct GameDriver driver_spnchotj;
extern struct GameDriver driver_spnchout;
extern struct GameDriver driver_sqixbl;
extern struct GameDriver driver_superqix;
extern struct GameDriver driver_ssi;
extern struct GameDriver driver_sstingry;
extern struct GameDriver driver_svolly91;
extern struct GameDriver driver_svolley;
extern struct GameDriver driver_svolleyk;
extern struct GameDriver driver_ssozumo;
extern struct GameDriver driver_ttmahjng;
extern struct GameDriver driver_tnk3;
extern struct GameDriver driver_tagteam;
extern struct GameDriver driver_tail2nos;
extern struct GameDriver driver_tnk3j;
extern struct GameDriver driver_targ;
extern struct GameDriver driver_tknight;
extern struct GameDriver driver_teedoff;
extern struct GameDriver driver_tehkanwc;
extern struct GameDriver driver_terracra;
extern struct GameDriver driver_terracre;
extern struct GameDriver driver_terracrb;
extern struct GameDriver driver_terrafu;
extern struct GameDriver driver_terraf;
extern struct GameDriver driver_3stooges;
extern struct GameDriver driver_thundfox;
extern struct GameDriver driver_tndrcade;
extern struct GameDriver driver_tigerhj;
extern struct GameDriver driver_tigerhb1;
extern struct GameDriver driver_tigerhb2;
extern struct GameDriver driver_tigerh;
extern struct GameDriver driver_tigerh2;
extern struct GameDriver driver_tigeroad;
extern struct GameDriver driver_timesol1;
extern struct GameDriver driver_timesold;
extern struct GameDriver driver_timetunl;
extern struct GameDriver driver_tinstar;
extern struct GameDriver driver_toggle;
extern struct GameDriver driver_tokiob;
extern struct GameDriver driver_tokio;
extern struct GameDriver driver_tndrcadj;
extern struct GameDriver driver_topsecex;
extern struct GameDriver driver_toramich;
extern struct GameDriver driver_tdfeverj;
extern struct GameDriver driver_tdfever;
extern struct GameDriver driver_triviasp;
extern struct GameDriver driver_triviabb;
extern struct GameDriver driver_triviag1;
extern struct GameDriver driver_triviag2;
extern struct GameDriver driver_triviayp;
extern struct GameDriver driver_tubeit;
extern struct GameDriver driver_turbofrc;
extern struct GameDriver driver_twineagl;
extern struct GameDriver driver_usclssic;
extern struct GameDriver driver_ultraman;
extern struct GameDriver driver_usvsthem;
extern struct GameDriver driver_valtric;
extern struct GameDriver driver_vangrdce;
extern struct GameDriver driver_vanguard;
extern struct GameDriver driver_vangrd2;
extern struct GameDriver driver_vastar;
extern struct GameDriver driver_vastar2;
extern struct GameDriver driver_venture4;
extern struct GameDriver driver_venture;
extern struct GameDriver driver_venture2;
extern struct GameDriver driver_victorba;
extern struct GameDriver driver_victroad;
extern struct GameDriver driver_victory;
extern struct GameDriver driver_viofight;
extern struct GameDriver driver_wrofaero;
extern struct GameDriver driver_waterski;
extern struct GameDriver driver_weststry;
extern struct GameDriver driver_whodunit;
extern struct GameDriver driver_wildfang;
extern struct GameDriver driver_wwestern;
extern struct GameDriver driver_wwester1;
extern struct GameDriver driver_wiping;
extern struct GameDriver driver_wiseguy;
extern struct GameDriver driver_wizt;
extern struct GameDriver driver_wiz;
extern struct GameDriver driver_wc90;
extern struct GameDriver driver_worldwar;
extern struct GameDriver driver_xsleenab;
extern struct GameDriver driver_xsleena;
extern struct GameDriver driver_yamyam;
extern struct GameDriver driver_yamato;
extern struct GameDriver driver_yamato2;
extern struct GameDriver driver_yesnoj;
extern struct GameDriver driver_youma;
extern struct GameDriver driver_yuyugogo;
extern struct GameDriver driver_zarzon;
extern struct GameDriver driver_zerozone;
extern struct GameDriver driver_zingzip;
extern struct GameDriver driver_zodiack;
extern struct GameDriver driver_zookeep;
extern struct GameDriver driver_zookeep2;
extern struct GameDriver driver_zookeep3;
const struct GameDriver *drivers[] =
{
&driver_99lstwra,
&driver_99lstwar,
&driver_aso,
&driver_hatena,
&driver_aerofgtb,
&driver_aerofgtc,
&driver_aerofgt,
&driver_aeroboto,
&driver_koshien,
&driver_airbustr,
&driver_airwolf,
&driver_alcon,
&driver_alpine,
&driver_alpinea,
&driver_ambush,
&driver_horshoes,
&driver_appoooh,
&driver_arabiana,
&driver_arabian,
&driver_arbalest,
&driver_argus,
&driver_arkarea,
&driver_armwrest,
&driver_armedf,
&driver_ashura,
&driver_ashurau,
&driver_athena,
&driver_baluba,
&driver_bankp,
&driver_btlfield,
&driver_battlane,
&driver_battlan2,
&driver_battlan3,
&driver_berlwall,
&driver_berlwalt,
&driver_bermudaj,
&driver_bermudaa,
&driver_bermudat,
&driver_berzerk,
&driver_berzerk1,
&driver_bigkarnk,
&driver_bigprowr,
&driver_bioatack,
&driver_biomtoy,
&driver_bking2,
&driver_blandia,
&driver_blasto,
//arkanoid &driver_arkbloc2,
&driver_blockade,
&driver_blocken,
&driver_bloodbro,
&driver_blueprnj,
&driver_blueprnt,
&driver_boblbobl,
&driver_bogeyman,
&driver_bjtwin,
&driver_bowlrama,
&driver_bublbobr,
&driver_bubbobr1,
&driver_bublbobl,
&driver_butasan,
&driver_cachat,
&driver_calibr50,
&driver_cameltry,
&driver_cameltru,
&driver_challeng,
&driver_champbbj,
&driver_champbb2,
&driver_champbas,
&driver_champwrj,
&driver_champwru,
&driver_champwr,
//atarisy2 &driver_csprint,
&driver_cheyenne,
&driver_cshift,
&driver_chiller,
&driver_chopper,
&driver_circus,
&driver_claypign,
&driver_combat,
&driver_comotion,
&driver_clbowl,
&driver_cop01,
&driver_cop01a,
&driver_cracksht,
&driver_crash,
&driver_crbaloon,
&driver_crbalon2,
&driver_crazyblk,
&driver_cclimbr2,
&driver_crimecj,
&driver_crimecu,
&driver_crimec,
&driver_crossbow,
&driver_cubybop,
&driver_curvebal,
&driver_dcon,
&driver_ddayc,
&driver_dday,
//cps1 &driver_ghoulsj,
&driver_dangar,
&driver_dangar2,
&driver_dangarb,
&driver_powj,
&driver_deadconj,
&driver_deadconx,
&driver_dinorexj,
&driver_dinorexu,
&driver_dinorex,
&driver_dogfight,
&driver_dogosoke,
&driver_dondokod,
&driver_dotrikun,
&driver_dotriku2,
&driver_dbldyn,
&driver_downtown,
&driver_drgnunit,
&driver_driftout,
&driver_driveout,
&driver_dynduke,
&driver_eggs,
&driver_elecyoyo,
&driver_elecyoy2,
&driver_elevatob,
&driver_elevator,
&driver_empcityj,
&driver_empcity,
&driver_euroch92,
&driver_wc90b,
&driver_excthour,
&driver_exctscca,
&driver_exctsccb,
&driver_exctscc2,
&driver_exctsccr,
&driver_exerizrb,
&driver_f1dreamb,
&driver_f1dream,
&driver_flstory,
&driver_flstoryj,
&driver_fantasyj,
&driver_fantasy,
&driver_sqbert,
&driver_fax,
&driver_fitegolf,
&driver_fhawk,
&driver_ftsoccer,
&driver_finalbj,
&driver_finalb,
&driver_fireone,
&driver_fitter,
&driver_flashgal,
&driver_footchmp,
&driver_formatz,
&driver_frenzy,
&driver_friskyt,
&driver_frontlin,
&driver_funkybee,
&driver_fnkyfish,
&driver_suprmou2,
&driver_galivan2,
&driver_galivan,
&driver_galpanic,
&driver_gangwars,
&driver_gangwarb,
&driver_gensitou,
&driver_getstarj,
&driver_getstarb,
&driver_gimeabrk,
&driver_ginganin,
&driver_gladiatr,
&driver_yamagchi,
&driver_gghost,
&driver_goindol,
&driver_goldmedl,
&driver_gotya,
&driver_gtmre,
&driver_gtmr,
&driver_gsword,
&driver_gridiron,
&driver_growlu,
&driver_growl,
&driver_getstar,
&driver_gwar,
&driver_gwara,
&driver_gwarb,
&driver_gwarj,
&driver_gunfront,
&driver_gunbird,
&driver_gundealr,
&driver_gundeala,
&driver_gunfronj,
&driver_gyrodine,
&driver_hal21j,
&driver_hal21,
&driver_hanaawas,
&driver_hardhat,
&driver_hardhead,
&driver_hardhedb,
&driver_hthero,
&driver_hattrick,
&driver_hatris,
&driver_heberpop,
&driver_hexa,
&driver_hwrace,
&driver_hitnmis2,
&driver_hitnmiss,
&driver_hitice,
&driver_homo,
&driver_hustle,
&driver_ikari3,
&driver_ikarijpb,
&driver_ikarijp,
&driver_ikari,
&driver_insector,
&driver_intrepid,
&driver_intrepi2,
&driver_jackrabt,
&driver_jackrab2,
&driver_jackrabs,
&driver_joyfulr,
&driver_jungleh,
&driver_junglek,
&driver_junglkj2,
&driver_kangaroa,
&driver_kangarob,
&driver_kangaroo,
&driver_kaos,
&driver_karatblu,
&driver_karatblz,
&driver_karianx,
&driver_kikstart,
&driver_killcom,
&driver_kncljoe,
&driver_kncljoea,
&driver_kodure,
&driver_legofair,
&driver_kram,
&driver_kram2,
&driver_krull,
&driver_kurikint,
&driver_kurikina,
&driver_kyros,
&driver_lsasquad,
&driver_lasso,
&driver_ledstorm,
&driver_lkageb,
&driver_lkageb2,
&driver_lkageb3,
&driver_lkage,
&driver_leprechn,
&driver_liquidku,
&driver_liquidk,
&driver_logicpro,
&driver_logicpr2,
&driver_mach3,
&driver_m79amb,
&driver_machomou,
&driver_madcrash,
&driver_mplanets,
&driver_magix,
&driver_mgakuen2,
&driver_mgakuen,
&driver_mjnquest,
&driver_mjnquesb,
&driver_majest12,
&driver_maniach,
&driver_maniach2,
&driver_marvins,
&driver_masterw,
&driver_matmania,
&driver_megaforc,
//cps1 &driver_mtwins,
&driver_megaznik,
&driver_megatack,
&driver_mermaid,
&driver_metafox,
&driver_minigolf,
&driver_minigol2,
&driver_minivadr,
&driver_mizubaku,
&driver_moguchan,
&driver_mole,
&driver_momoko,
&driver_monymony,
&driver_mtrap3,
&driver_mtrap4,
&driver_mtrap,
&driver_mrjong,
&driver_mnchmobl,
&driver_mnight,
&driver_mystston,
&driver_nametune,
&driver_nastar,
&driver_nastarw,
&driver_nibbler,
&driver_nibblera,
&driver_nstocker,
&driver_ninjemak,
&driver_gaiden,
&driver_ninjakd2,
&driver_ninjak2a,
&driver_ninjak2b,
&driver_ninjakj,
&driver_ninjak,
&driver_ryukendn,
&driver_nunchaku,
&driver_otwalls,
&driver_ohmygod,
&driver_ogonsiro,
&driver_pow,
&driver_palamed,
&driver_pang,
&driver_pangb,
&driver_pepper2,
&driver_percuss,
&driver_pbaction,
&driver_pbactio2,
&driver_pinbos,
&driver_pinbo,
&driver_pballoon,
&driver_pipedrm,
&driver_thepit,
&driver_plgirls,
&driver_plgirls2,
&driver_plotting,
&driver_pkladies,
&driver_polyplay,
&driver_pompingw,
&driver_portman,
&driver_potogold,
&driver_powerins,
&driver_pspikes,
&driver_prehislu,
&driver_prehisle,
&driver_psychic5,
&driver_psychosj,
&driver_psychos,
&driver_pulirulj,
&driver_pulirula,
&driver_punchout,
//cps1 &driver_punishrj,
//cps1 &driver_punishru,
//cps1 &driver_punisher,
&driver_puzbobb,
&driver_puzznic,
&driver_qbertjp,
&driver_qbert,
&driver_qbertqub,
&driver_qix,
&driver_qixa,
&driver_qixb,
&driver_qix2,
&driver_qzchikyu,
&driver_qcrayon,
&driver_qcrayon2,
&driver_quizhq,
&driver_qjinsei,
&driver_qzquest,
&driver_qzshowby,
&driver_qtorimon,
&driver_rpunch,
&driver_rabiolep,
&driver_rdaction,
&driver_radrad,
&driver_raidena,
&driver_raidenk,
&driver_raiden,
&driver_raimais,
&driver_rambo3,
&driver_rambo3a,
&driver_rastsag2,
&driver_reactor,
&driver_repulse,
&driver_rescrdsa,
&driver_rescraid,
&driver_retofin1,
&driver_retofin2,
&driver_retofinv,
&driver_ripcord,
&driver_robotbwl,
&driver_rranger,
&driver_roundup,
&driver_route16b,
&driver_route16,
&driver_royalmah,
&driver_rugrats,
&driver_runark,
&driver_srdmissn,
&driver_sercharu,
&driver_searchar,
&driver_safarir,
&driver_tsamurai,
&driver_tsamura2,
//cps1 &driver_wofa,
&driver_sasuke,
&driver_satansat,
//cps1 &driver_slammast,
&driver_saturn,
&driver_sauro,
&driver_scionc,
&driver_scion,
&driver_scregg,
&driver_screwloo,
&driver_sfposeid,
&driver_sectrzon,
&driver_seicross,
&driver_sngkace,
//cps1 &driver_mercsj,
&driver_senjyo,
&driver_sentetst,
&driver_shadoww,
&driver_shangha3,
&driver_shanghai,
&driver_sharkatt,
&driver_shisen,
&driver_showdown,
&driver_sichuana,
&driver_sichuan2,
&driver_sidetrac,
&driver_silentd,
&driver_skyadvnt,
&driver_skyfox,
&driver_skylancr,
&driver_skysoldr,
&driver_skywolf,
&driver_skywolf2,
&driver_slapbtuk,
&driver_slapbtjp,
&driver_slapfigh,
&driver_snakjack,
&driver_snakepit,
&driver_solarwar,
&driver_solfigtr,
&driver_sonofphx,
&driver_sonicwi,
&driver_sdungeon,
&driver_spacedx,
&driver_spaceskr,
&driver_stactics,
&driver_speakres,
&driver_spectar1,
&driver_spectar,
&driver_speedbal,
&driver_spiders,
&driver_spiders2,
&driver_spiker,
&driver_spinlbrj,
&driver_spinlbru,
&driver_spinlbrk,
&driver_splash,
&driver_starcrus,
&driver_starfire,
&driver_starfore,
&driver_starforc,
&driver_stinger,
&driver_stocker,
&driver_storming,
&driver_stratvxb,
&driver_stratvox,
&driver_stfight,
&driver_sfootbal,
&driver_streetsj,
&driver_streets1,
&driver_streetsm,
&driver_sboblbob,
&driver_sbbros,
&driver_sbasebal,
&driver_sformula,
&driver_marukin,
&driver_suprmous,
&driver_spang,
&driver_spnchotj,
&driver_spnchout,
&driver_sqixbl,
&driver_superqix,
&driver_ssi,
&driver_sstingry,
&driver_svolly91,
&driver_svolley,
&driver_svolleyk,
&driver_ssozumo,
&driver_ttmahjng,
&driver_tnk3,
&driver_tagteam,
&driver_tail2nos,
&driver_tnk3j,
&driver_targ,
&driver_tknight,
&driver_teedoff,
&driver_tehkanwc,
&driver_terracra,
&driver_terracre,
&driver_terracrb,
&driver_terrafu,
&driver_terraf,
// &driver_tetrist,
&driver_3stooges,
&driver_thundfox,
&driver_tndrcade,
&driver_tigerhj,
&driver_tigerhb1,
&driver_tigerhb2,
&driver_tigerh,
&driver_tigerh2,
&driver_tigeroad,
&driver_timesol1,
&driver_timesold,
&driver_timetunl,
&driver_tinstar,
&driver_toggle,
&driver_tokiob,
&driver_tokio,
&driver_tndrcadj,
&driver_topsecex,
&driver_toramich,
&driver_tdfeverj,
&driver_tdfever,
&driver_triviasp,
&driver_triviabb,
&driver_triviag1,
&driver_triviag2,
&driver_triviayp,
&driver_tubeit,
&driver_turbofrc,
&driver_twineagl,
&driver_usclssic,
&driver_ultraman,
&driver_usvsthem,
&driver_valtric,
&driver_vangrdce,
&driver_vanguard,
&driver_vangrd2,
&driver_vastar,
&driver_vastar2,
&driver_venture4,
&driver_venture,
&driver_venture2,
&driver_victorba,
&driver_victroad,
&driver_victory,
&driver_viofight,
&driver_wrofaero,
//cps1 &driver_wof,
&driver_waterski,
&driver_weststry,
&driver_whodunit,
&driver_wildfang,
&driver_wwestern,
&driver_wwester1,
&driver_wiping,
&driver_wiseguy,
&driver_wizt,
&driver_wiz,
&driver_wc90,
&driver_worldwar,
&driver_xsleenab,
&driver_xsleena,
&driver_yamyam,
&driver_yamato,
&driver_yamato2,
&driver_yesnoj,
&driver_youma,
&driver_yuyugogo,
&driver_zarzon,
&driver_zerozone,
&driver_zingzip,
&driver_zodiack,
&driver_zookeep,
&driver_zookeep2,
&driver_zookeep3,
0 /* end of array */
};
|
the_stack_data/150139747.c | /*! \file mirror.c
*
* LTSW MIRROR command.
*/
/*
* This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
*
* Copyright 2007-2020 Broadcom Inc. All rights reserved.
*/
#if defined(BCM_LTSW_SUPPORT)
#include <appl/diag/system.h>
#include <appl/diag/ltsw/cmdlist.h>
#include <shared/bsl.h>
#include <sal/sal_types.h>
#include <bcm/mirror.h>
#include <bcm/init.h>
#include <bcm/stack.h>
#include <bcm_int/ltsw/mirror.h>
#include <bcm_int/ltsw/port.h>
#include <bcm_int/ltsw/virtual.h>
/******************************************************************************
* Private functions
*/
/*!
* \brief Callback function to show Mirror destination.
*
* \param [in] unit Unit number.
* \param [in] mirror_dest Mirror destination structure.
* \param [in] user_data User data.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
static int
show_mirror_destination_cb(int unit, bcm_mirror_destination_t *mirror_dest,
void *user_data)
{
int *count = (int *)user_data, rv;
if (mirror_dest == NULL || user_data == NULL) {
return BCM_E_PARAM;
}
(*count)++;
cli_out("Mirror Dest %2d: ", *count);
cli_out("Mirror ID: %2d; ",
BCM_GPORT_MIRROR_GET(mirror_dest->mirror_dest_id));
if (mirror_dest->flags & BCM_MIRROR_DEST_TUNNEL_L2) {
cli_out("%s ", "L2 Tunnel to");
}
if (mirror_dest->flags & BCM_MIRROR_DEST_TUNNEL_IP_GRE) {
cli_out("IPv%d GRE Tunnel\n", mirror_dest->version);
if (4 == mirror_dest->version) {
char buffer[16];
format_ipaddr(buffer, mirror_dest->src_addr);
cli_out("\tSrc IP=%s\n", buffer);
format_ipaddr(buffer, mirror_dest->dst_addr);
cli_out("\tDst IP=%s\n", buffer);
} else if (6 == mirror_dest->version) {
char buffer[64];
format_ip6addr(buffer, mirror_dest->src6_addr);
cli_out("\tSrc IP=%s\n", buffer);
format_ip6addr(buffer, mirror_dest->dst6_addr);
cli_out("\tDst IP=%s\n", buffer);
cli_out("\tFlow Label=0x%04x\n", mirror_dest->flow_label);
}
cli_out("\tsrc_mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
mirror_dest->src_mac[0], mirror_dest->src_mac[1],
mirror_dest->src_mac[2], mirror_dest->src_mac[3],
mirror_dest->src_mac[4], mirror_dest->src_mac[5]);
cli_out("\tdst_mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
mirror_dest->dst_mac[0], mirror_dest->dst_mac[1],
mirror_dest->dst_mac[2], mirror_dest->dst_mac[3],
mirror_dest->dst_mac[4], mirror_dest->dst_mac[5]);
cli_out("\tvlan_id=0x%04x\n", mirror_dest->vlan_id);
cli_out("\ttpid=0x%04x\n", mirror_dest->tpid);
cli_out("\tttl=%d\n", mirror_dest->ttl);
cli_out("\ttos=%d\n", mirror_dest->tos);
cli_out("\tmirrored to ");
}
if (mirror_dest->flags & BCM_MIRROR_DEST_PAYLOAD_UNTAGGED) {
cli_out("%s ", "Payload Untagged");
}
if (BCM_GPORT_IS_LOCAL(mirror_dest->gport)) {
cli_out("local port %s",
BCM_PORT_NAME(unit, BCM_GPORT_LOCAL_GET(mirror_dest->gport)));
} else if (BCM_GPORT_IS_MODPORT(mirror_dest->gport)) {
bcm_port_t local_port;
rv = bcm_port_local_get(unit, mirror_dest->gport, &local_port);
if (rv != BCM_E_NONE) {
cli_out("modport %d/%d",
BCM_GPORT_MODPORT_MODID_GET(mirror_dest->gport),
BCM_GPORT_MODPORT_PORT_GET(mirror_dest->gport));
} else {
cli_out("local port %s", BCM_PORT_NAME(unit, local_port));
}
} else if (BCM_GPORT_IS_TRUNK(mirror_dest->gport)) {
cli_out("trunk group %d", BCM_GPORT_TRUNK_GET(mirror_dest->gport));
} else {
cli_out("GPORT 0x%08X", mirror_dest->gport);
}
cli_out("\n");
return BCM_E_NONE;
}
/*!
* \brief Mirror destination show subcmd handler.
*
* \param [in] unit Unit number.
* \param [in] arg Arg structure for parsing arguments.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
STATIC cmd_result_t
cmd_ltsw_mirror_dest_show(int unit, args_t *arg)
{
int rv, count = 0;
rv = bcm_mirror_destination_traverse(unit, show_mirror_destination_cb,
&count);
if (BCM_FAILURE(rv)) {
cli_out("%s bcm_mirror_destination_traverse() failed %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
return CMD_OK;
}
/*!
* \brief Mirror destination cmd handler.
*
* \param [in] unit Unit number.
* \param [in] arg Arg structure for parsing arguments.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
STATIC cmd_result_t
cmd_ltsw_mirror_dest(int unit, args_t *arg)
{
parse_table_t pt;
char *cmd = NULL;
bcm_ip_t src_ip = 0, dest_ip = 0;
bcm_ip6_t src_ip6, dest_ip6;
bcm_mac_t src_mac, dest_mac;
bcm_gport_t mirror_dest_id = 0;
bcm_port_t src_port = 0, dest_port = 0;
uint32_t flow_lable = 0;
uint32_t mirror_port_flags = 0;
int vlan_id = -1, tpid = -1, ttl = 0,tos = 0, version = 0;
int mode = 0, tunnel = 0, rv;
bool strip_vlan = false;
bcm_mirror_destination_t *mirror_dest = NULL;
char *modeList[] =
{"OFF", "Ingress", "Egress", "EgressTrue", "IngressEgress", NULL};
char *tunnelList[] = {"OFF","L2", "GRE", NULL};
cmd_result_t cmd_rv = CMD_OK;
if ((cmd = ARG_GET(arg)) == NULL) {
cmd_rv = CMD_USAGE;
goto exit;
}
if (sal_strcasecmp("show", cmd) == 0) {
cmd_rv = cmd_ltsw_mirror_dest_show(unit, arg);
goto exit;
}
sal_memset(src_ip6, 0, sizeof(bcm_ip6_t));
sal_memset(dest_ip6, 0, sizeof(bcm_ip6_t));
sal_memset(src_mac, 0, sizeof(bcm_mac_t));
sal_memset(dest_mac, 0, sizeof(bcm_mac_t));
parse_table_init(unit, &pt);
parse_table_add(&pt, "Id", PQ_DFL | PQ_INT,0, &mirror_dest_id, NULL);
parse_table_add(&pt, "Mode", PQ_DFL | PQ_MULTI,(void *)(0),
&mode, modeList);
parse_table_add(&pt, "Tunnel", PQ_DFL | PQ_MULTI,(void *)(0),
&tunnel, tunnelList);
parse_table_add(&pt, "SrcPort", PQ_DFL | PQ_PORT, 0, &src_port, NULL);
parse_table_add(&pt, "DestPort", PQ_DFL | PQ_PORT, 0, &dest_port, NULL);
parse_table_add(&pt, "SrcIP", PQ_DFL | PQ_IP, 0, (void *)&src_ip, NULL);
parse_table_add(&pt, "DestIP", PQ_DFL | PQ_IP, 0, (void *)&dest_ip, NULL);
parse_table_add(&pt, "SrcIP6", PQ_DFL | PQ_IP6, 0, (void *)&src_ip6, NULL);
parse_table_add(&pt, "DestIP6", PQ_DFL | PQ_IP6, 0,
(void *)&dest_ip6, NULL);
parse_table_add(&pt, "SrcMAC", PQ_DFL|PQ_MAC, 0, (void *)src_mac, NULL);
parse_table_add(&pt, "DestMAC", PQ_DFL|PQ_MAC, 0, (void *)dest_mac, NULL);
parse_table_add(&pt, "VLAN", PQ_DFL|PQ_INT, 0, (void *)&vlan_id, NULL);
parse_table_add(&pt, "tpid", PQ_DFL|PQ_INT, 0, (void *)&tpid, NULL);
parse_table_add(&pt, "Version", PQ_DFL|PQ_INT, 0, (void *)&version, NULL);
parse_table_add(&pt, "TTL", PQ_DFL|PQ_INT, 0, (void *)&ttl, NULL);
parse_table_add(&pt, "TOS", PQ_DFL|PQ_INT, 0, (void *)&tos, NULL);
parse_table_add(&pt, "FlowLable", PQ_DFL|PQ_INT, 0,
(void *)&flow_lable, NULL);
parse_table_add(&pt, "NoVLAN", PQ_DFL|PQ_BOOL, 0,
(void *)&strip_vlan, NULL);
if (parse_arg_eq(arg, &pt) < 0 || ARG_CNT(arg) > 0) {
cli_out("%s: Invalid option %s\n", ARG_CMD(arg), ARG_CUR(arg));
parse_arg_eq_done(&pt);
cmd_rv = CMD_USAGE;
goto exit;
}
parse_arg_eq_done(&pt);
/* Allocate memory from heap to avoid stack overflow. */
mirror_dest = sal_alloc(sizeof(bcm_mirror_destination_t),
"CLI Mirror Dest");
if (mirror_dest == NULL) {
cmd_rv = CMD_FAIL;
goto exit;
}
bcm_mirror_destination_t_init(mirror_dest);
switch (mode) {
case 1:
mirror_port_flags |= BCM_MIRROR_PORT_INGRESS;
break;
case 2:
mirror_port_flags |= BCM_MIRROR_PORT_EGRESS;
break;
case 3:
mirror_port_flags |= BCM_MIRROR_PORT_EGRESS_TRUE;
break;
case 4:
mirror_port_flags |=
(BCM_MIRROR_PORT_INGRESS | BCM_MIRROR_PORT_EGRESS);
break;
default:
break;
}
switch (tunnel) {
case 1:
mirror_dest->flags |= BCM_MIRROR_DEST_TUNNEL_L2;
sal_memcpy(mirror_dest->src_mac, src_mac, sizeof(src_mac));
sal_memcpy(mirror_dest->dst_mac, dest_mac, sizeof(dest_mac));
mirror_dest->vlan_id = (bcm_vlan_t) (vlan_id & 0xffff);
mirror_dest->tpid = (uint16_t) (tpid & 0xffff);
break;
case 2:
mirror_dest->flags |= BCM_MIRROR_DEST_TUNNEL_IP_GRE;
sal_memcpy(mirror_dest->src_mac, src_mac, sizeof(src_mac));
sal_memcpy(mirror_dest->dst_mac, dest_mac, sizeof(dest_mac));
mirror_dest->vlan_id = (bcm_vlan_t) (vlan_id & 0xffff);
mirror_dest->tpid = (uint16_t) (tpid & 0xffff);
mirror_dest->src_addr = src_ip;
mirror_dest->dst_addr = dest_ip;
mirror_dest->ttl = ttl;
mirror_dest->tos = tos;
mirror_dest->flow_label = flow_lable;
mirror_dest->version = version;
sal_memcpy(mirror_dest->src6_addr, src_ip6, sizeof(src_ip6));
sal_memcpy(mirror_dest->dst6_addr, dest_ip6, sizeof(dest_ip6));
break;
default:
break;
}
if (strip_vlan) {
mirror_dest->flags |= BCM_MIRROR_DEST_PAYLOAD_UNTAGGED;
}
if (!BCM_GPORT_IS_SET(dest_port)) {
rv = bcm_port_gport_get(unit, dest_port, &dest_port);
if (BCM_FAILURE(rv)) {
cli_out("Illegal port [%d]\n", dest_port);
cmd_rv = CMD_FAIL;
goto exit;
}
}
mirror_dest->gport = dest_port;
if (mirror_dest_id != 0) {
mirror_dest->flags |= BCM_MIRROR_DEST_WITH_ID;
mirror_dest->mirror_dest_id = mirror_dest_id;
}
if (sal_strcasecmp("create", cmd) == 0) {
rv = bcm_mirror_destination_create(unit, mirror_dest);
if (BCM_FAILURE(rv)) {
cli_out("%s bcm_mirror_destination_create() failed %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
cmd_rv = CMD_FAIL;
goto exit;
}
cli_out(" Mirror Id = 0x%x\n", mirror_dest->mirror_dest_id);
cmd_rv = CMD_OK;
goto exit;
} else if (sal_strcasecmp("add", cmd) == 0) {
rv = bcm_mirror_port_dest_add(unit, src_port,
mirror_port_flags, mirror_dest_id);
if (BCM_FAILURE(rv)) {
cli_out("%s bcm_mirror_port_dest_add() failed %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
cmd_rv = CMD_FAIL;
goto exit;
}
cmd_rv = CMD_OK;
goto exit;
} else if (sal_strcasecmp("destroy", cmd) == 0) {
if (0 == mirror_dest_id) {
cli_out("%s mirror destination id is missing\n", ARG_CMD(arg));
cmd_rv = CMD_FAIL;
goto exit;
}
rv = bcm_mirror_destination_destroy(unit, mirror_dest_id);
if (BCM_FAILURE(rv)) {
cli_out("%s bcm_mirror_destination_destroy failed() %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
cmd_rv = CMD_FAIL;
goto exit;
}
cmd_rv = CMD_OK;
goto exit;
} else if (sal_strcasecmp("delete", cmd) == 0) {
rv = bcm_mirror_port_dest_delete(unit, src_port,
mirror_port_flags, mirror_dest_id);
if (BCM_FAILURE(rv)) {
cli_out("%s bcm_mirror_port_dest_delete failed %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
cmd_rv = CMD_FAIL;
goto exit;
}
cmd_rv = CMD_OK;
goto exit;
}
cmd_rv = CMD_OK;
goto exit;
exit:
if (mirror_dest != NULL) {
sal_free(mirror_dest);
mirror_dest = NULL;
}
return cmd_rv;
}
/*!
* \brief Init Mirror module.
*
* \param [in] unit Unit number.
* \param [in] arg Arg structure for parsing arguments.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
STATIC cmd_result_t
cmd_ltsw_mirror_init(int unit, args_t *arg)
{
int rv;
if (ARG_CNT(arg) > 0) {
return CMD_USAGE;
}
rv = bcm_mirror_init(unit);
if (rv < 0) {
cli_out("%s: ERROR: bcm_mirror_init failed %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
return CMD_OK;
}
/*!
* \brief Show Mirror configuration on a port.
*
* \param [in] unit Unit number.
* \param [in] port Source port.
* \param [in] destmod Mirror destination modid.
* \param [in] destport Mirror destination port.
* \param [in] flags Mirror flags.
*/
static void
show_mirror_port(int unit, int port, int dstmod, int dstport, uint32 flags)
{
int show_dest, rv;
bcm_port_t local_port, port_out;
bcm_gport_t gport;
char *mstr;
bcmi_ltsw_virtual_vp_info_t vp_info;
char *vptype = "";
show_dest = 1;
if (flags & BCM_MIRROR_PORT_INGRESS) {
if (flags & (BCM_MIRROR_PORT_EGRESS)) {
mstr = "Mirror all";
} else {
mstr = "Mirror ingress";
}
} else if (flags & BCM_MIRROR_PORT_EGRESS) {
mstr = "Mirror egress";
} else if (flags & BCM_MIRROR_PORT_ENABLE) {
mstr = "Mirror";
} else {
mstr = "-";
show_dest = 0;
}
if (BCM_GPORT_IS_SET(port)) {
rv = bcmi_ltsw_port_gport_validate(unit, port, &port_out);
if (rv < 0) {
cli_out("bcmi_ltsw_port_gport_validate: %s\n",
bcm_errmsg(rv));
return;
}
rv = bcmi_ltsw_virtual_vp_info_get(unit, port_out, &vp_info);
if (rv < 0) {
cli_out("bcmi_ltsw_virtual_vp_info_get: %s\n",
bcm_errmsg(rv));
return;
}
if (vp_info.flags & BCMI_LTSW_VIRTUAL_VP_TYPE_MPLS) {
vptype = "Mpls";
} else if (vp_info.flags & BCMI_LTSW_VIRTUAL_VP_TYPE_FLOW) {
vptype = "Flow";
}
cli_out("%s port(%#x): %s", vptype, port, mstr);
} else {
cli_out("%4s: %s", bcm_port_name(unit, port), mstr);
}
if (show_dest) {
if (BCM_GPORT_IS_MODPORT(dstport)) {
gport = dstport;
dstmod = BCM_GPORT_MODPORT_MODID_GET(gport);
dstport = BCM_GPORT_MODPORT_PORT_GET(gport);
} else {
BCM_GPORT_MODPORT_SET(gport, dstmod, dstport);
}
if (bcm_port_local_get(unit, gport, &local_port) != BCM_E_NONE) {
local_port = -1;
}
if (BCM_GPORT_IS_TRUNK(dstport)) {
cli_out(" to trunk group %d", BCM_GPORT_TRUNK_GET(dstport));
} else if (flags & BCM_MIRROR_PORT_DEST_TRUNK) {
cli_out(" to trunk group %d", dstport);
} else if (local_port >= 0) {
cli_out(" to local port %s", bcm_port_name(unit, local_port));
} else {
cli_out(" to module %d, port %d", dstmod, dstport);
}
}
cli_out("\n");
}
/*!
* \brief Mirror port cmd handler.
*
* \param [in] unit Unit number.
* \param [in] arg Arg structure for parsing arguments.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
STATIC cmd_result_t
cmd_ltsw_mirror_port(int unit, args_t *arg)
{
parse_table_t pt;
char *cmd = NULL;
bcm_pbmp_t pbm;
bcm_port_t port, destport = -1;
bcm_port_config_t pcfg;
int destmod = -1, mode = -1, desttrunk = -1, rv, count = 0;
char *modeList[] = {"OFF", "ON", "Ingress", "Egress", "All", NULL};
uint32 flags = 0;
if ((cmd = ARG_GET(arg)) == NULL) {
return CMD_USAGE;
}
if (bcm_port_config_get(unit, &pcfg) != BCM_E_NONE) {
cli_out("%s: Error: bcm ports not initialized\n", ARG_CMD(arg));
return CMD_FAIL;
}
if ((ARG_CNT(arg) == 0) && parse_cmp("SHow", cmd, '\0')) {
BCM_PBMP_ITER(pcfg.all, port) {
destport = destmod = -1;
rv = bcm_mirror_port_get(unit, port, &destmod, &destport, &flags);
if (rv < 0) {
cli_out("%s: bcm_mirror_port_get: %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
if (flags != 0) {
count++;
show_mirror_port(unit, port, destmod, destport, flags);
}
}
if (count == 0) {
cli_out("%s: No mirror ports configured\n", ARG_CMD(arg));
}
return CMD_OK;
}
if (parse_bcm_pbmp(unit, cmd, &pbm) < 0) {
cli_out("%s: Error: unrecognized port bitmap: %s\n",
ARG_CMD(arg), cmd);
return CMD_FAIL;
}
BCM_PBMP_AND(pbm, pcfg.all);
if (BCM_PBMP_IS_NULL(pbm)) {
cli_out("%s: Error: unsupported port bitmap: %s\n",
ARG_CMD(arg), cmd);
return CMD_FAIL;
}
if (ARG_CNT(arg) == 0) {
BCM_PBMP_ITER(pbm, port) {
rv = bcm_mirror_port_get(unit, port, &destmod, &destport, &flags);
if (rv < 0) {
cli_out("%s: bcm_mirror_port_get: %s\n", ARG_CMD(arg),
bcm_errmsg(rv));
return CMD_FAIL;
}
show_mirror_port(unit, port, destmod, destport, flags);
}
return CMD_OK;
}
parse_table_init(unit, &pt);
parse_table_add(&pt, "DestPort", PQ_DFL|PQ_PORT,
(void *)(0), &destport, NULL);
parse_table_add(&pt, "DestModule", PQ_DFL|PQ_INT,
(void *)(0), &destmod, NULL);
parse_table_add(&pt, "DestTrunk", PQ_DFL|PQ_INT,
(void *)(0), &desttrunk, NULL);
parse_table_add(&pt, "Mode", PQ_DFL|PQ_MULTI,
(void *)(0), &mode, modeList);
if (parse_arg_eq(arg, &pt) < 0 || ARG_CNT(arg) > 0) {
cli_out("%s: Invalid option %s\n", ARG_CMD(arg), ARG_CUR(arg));
parse_arg_eq_done(&pt);
return CMD_USAGE;
}
parse_arg_eq_done(&pt);
if (mode < 0) {
cli_out("%s: must specify a mode\n", ARG_CMD(arg));
return CMD_USAGE;
}
if ((mode > 0) && (destport < 0) && (desttrunk < 0)) {
cli_out("%s: missing DestPort or DestTrunk\n", ARG_CMD(arg));
return CMD_USAGE;
}
if (destport > 0 && desttrunk > 0) {
cli_out("%s: cannot specify both DestPort and DestTrunk\n",
ARG_CMD(arg));
return CMD_USAGE;
}
switch (mode) {
case 1:
flags |= BCM_MIRROR_PORT_ENABLE;
break;
case 2:
flags |= BCM_MIRROR_PORT_INGRESS;
break;
case 3:
flags |= BCM_MIRROR_PORT_EGRESS;
break;
case 4:
flags |= (BCM_MIRROR_PORT_INGRESS | BCM_MIRROR_PORT_EGRESS);
break;
default:
break;
}
BCM_PBMP_ITER(pbm, port) {
rv = bcm_mirror_port_set(unit, port, destmod, destport, flags);
if (rv < 0) {
cli_out("%s: bcm_mirror_port_set: %s\n", ARG_CMD(arg),
bcm_errmsg(rv));
return CMD_FAIL;
}
}
return CMD_OK;
}
/*!
* \brief Show mirror configuration.
*
* \param [in] unit Unit number.
* \param [in] arg Arg structure for parsing arguments.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
STATIC cmd_result_t
cmd_ltsw_mirror_show(int unit, args_t *arg)
{
int rv, dest_size, dest_count = 0;
bcm_port_t port;
bcm_pbmp_t pbmp;
bcm_gport_t gport, mirror_dest[8];
int vp, i, fc, count = 0, first = TRUE;
uint32 flags[2] = {BCM_MIRROR_PORT_INGRESS, BCM_MIRROR_PORT_EGRESS};
uint32 vp_num;
bcm_mirror_destination_t destination;
bcmi_ltsw_virtual_vp_info_t vp_info;
if (ARG_CNT(arg) > 0) {
return CMD_USAGE;
}
rv = bcmi_ltsw_port_bitmap(unit, BCMI_LTSW_PORT_TYPE_ALL, &pbmp);
if (rv < 0) {
cli_out("%s: bcmi_ltsw_port_bitmap: %s\n", ARG_CMD(arg),
bcm_errmsg(rv));
return CMD_FAIL;
}
dest_size = 8;
BCM_PBMP_ITER(pbmp, port) {
for (fc = 0; fc < sizeof(flags) / sizeof(uint32); fc++) {
rv = bcm_mirror_port_dest_get(unit, port, flags[fc], dest_size,
mirror_dest, &dest_count);
if (rv < 0) {
cli_out("%s: bcm_mirror_port_dest_get: %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
if (dest_count != 0) {
for (i = 0; i < dest_count; i++) {
bcm_mirror_destination_t_init(&destination);
rv = bcm_mirror_destination_get(unit, mirror_dest[i],
&destination);
if (rv < 0) {
cli_out("%s: bcm_mirror_destination_get: %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
show_mirror_port(unit, port, 0, destination.gport,
flags[fc]);
}
count += dest_count;
}
}
}
rv = bcmi_ltsw_virtual_vp_num_get(unit, &vp_num);
if (rv < 0) {
cli_out("%s: bcmi_ltsw_virtual_vp_num_get: %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
for (vp = 0; vp < vp_num; vp++) {
for (fc = 0; fc < sizeof(flags) / sizeof(uint32); fc++) {
rv = bcmi_ltsw_virtual_vp_used_get(unit, vp, BCMI_LTSW_VP_TYPE_ANY);
if (rv == BCM_E_NOT_FOUND) {
/* Skip unused vp. */
continue;
}
rv = bcmi_ltsw_virtual_vp_info_get(unit, vp, &vp_info);
if (rv < 0) {
continue;
}
if (vp_info.flags & BCMI_LTSW_VIRTUAL_VP_TYPE_MPLS) {
BCM_GPORT_MPLS_PORT_ID_SET(gport, vp);
} else if (vp_info.flags & BCMI_LTSW_VIRTUAL_VP_TYPE_FLOW) {
BCM_GPORT_FLOW_PORT_ID_SET(gport, vp);
} else if (vp_info.flags & BCMI_LTSW_VIRTUAL_VP_TYPE_VPLAG) {
BCM_GPORT_VPLAG_PORT_ID_SET(gport, vp);
} else {
continue;
}
rv = bcm_mirror_port_dest_get(unit, gport, flags[fc], dest_size,
mirror_dest, &dest_count);
if (rv < 0) {
continue;
}
if (first) {
cli_out("-----------------------------------------\n");
first = FALSE;
}
if (dest_count != 0) {
for (i = 0; i < dest_count; i++) {
bcm_mirror_destination_t_init(&destination);
rv = bcm_mirror_destination_get(unit, mirror_dest[i],
&destination);
if (rv < 0) {
cli_out("%s: bcm_mirror_destination_get: %s\n",
ARG_CMD(arg), bcm_errmsg(rv));
return CMD_FAIL;
}
show_mirror_port(unit, gport, 0, destination.gport,
flags[fc]);
}
count += dest_count;
}
}
}
if (count == 0) {
cli_out("No mirror ports configured\n");
}
return CMD_OK;
}
/******************************************************************************
* Public Functions
*/
/*!
* \brief Mirror cmd handler.
*
* \param [in] unit Unit number.
* \param [in] arg Arg structure for parsing arguments.
*
* \retval CMD_OK Command completed successfully.
* \retval CMD_FAIL Command failed.
*/
cmd_result_t
cmd_ltsw_mirror(int unit, args_t *arg)
{
char *subcmd = NULL;
if ((subcmd = ARG_GET(arg)) == NULL) {
return CMD_USAGE;
}
if (!sal_strcasecmp(subcmd, "DEST")) {
return cmd_ltsw_mirror_dest(unit, arg);
} else if (!sal_strcasecmp(subcmd, "init")) {
return cmd_ltsw_mirror_init(unit, arg);
} else if (!sal_strcasecmp(subcmd, "Port")) {
return cmd_ltsw_mirror_port(unit, arg);
} else if (!sal_strcasecmp(subcmd, "SHow")) {
return cmd_ltsw_mirror_show(unit, arg);
} else {
return CMD_NOTIMPL;
}
return CMD_OK;
}
#endif /* BCM_LTSW_SUPPORT */
|
the_stack_data/5226.c | /*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#define RCSID0 "$Id$"
/*
* INTEL 80386 options
*/
#define THREE_PASS /* branch and offset optimization */
#define LISTING /* enable listing facilities */
#define RELOCATION /* generate relocation info */
#undef ADDR_T
#define ADDR_T long
#undef ALIGNWORD
#define ALIGNWORD 4
#undef ALIGNSECT
#define ALIGNSECT 4
|
the_stack_data/3261736.c | void main()
{
int a[5],max,i;
getid (a);
max=a[0];
for (i=1; i<5; i++)
if (max<a[i])
max=a[i];
printid(max);
} |
the_stack_data/332384.c | #include <stdio.h>
#ifndef NO_STDLIB_H
#include <stdlib.h>
#else
char *getenv();
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <time.h>
#define MAX_ENTRIES 2500
typedef struct {
char *name;
char *val;
} entry;
char *makeword(char *line, char stop);
char *fmakeword(FILE *f, char stop, int *len);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);
FILE *infp,*outfp;
main(int argc, char *argv[]) {
entry entries[MAX_ENTRIES];
register int x,m=0;
int cl;
char data[255],filename[255],file2[255],dir[255],command[255],time_str[20];
clock_t clocktime;
time_t curtime;
struct tm *loctime;
printf("Content-type: text/html%c%c",10,10);
curtime = time (NULL); /* Get the current time. */
loctime = localtime (&curtime); /* Convert to localtime representation.*/
strftime (time_str,20,"%H%M%S",loctime); /* Convert to string */
/* local directories */
sprintf(dir, "/export/home/httpd/htdocs/research/wavelets/plot/");
sprintf(filename, "out/wave_%s", getenv("REMOTE_HOST"));
if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
goto skip;
/* printf("This script should be referenced using ");
printf("<A HREF=\"waveplot.html\">Wavelet Plot</A>.%c",10);
exit(1);
*/
}
/* not sure what this does... */
if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
printf("<BODY>This script can only be used to decode form results. \n");
exit(1);
}
cl = atoi(getenv("CONTENT_LENGTH"));
/* decode the form data */
for(x=0;cl && (!feof(stdin));x++) {
m=x;
entries[x].val = fmakeword(stdin,'&',&cl);
plustospace(entries[x].val);
unescape_url(entries[x].val);
entries[x].name = makeword(entries[x].val,'=');
}
/* read in options */
if (strcmp(entries[1].name,"$dataset")==0) {
sprintf(command,"rm -f %s%s.opt",dir,filename);
system(command);
sprintf(file2,"%s%s.dat",dir,filename);}
else
sprintf(file2,"%s%s.opt",dir,filename);
/* remove previous gif & postscript files */
sprintf(command,"rm -f %s%s*.gif %s%s*.ps",dir,filename,dir,filename);
system(command);
/* write out options */
outfp = fopen(file2,"w");
for(x=0; x <= m; x++)
fprintf(outfp,"%s\n%s\n",entries[x].name,entries[x].val);
fclose(outfp);
skip:
/* construct IDL batch file */
sprintf(file2,"%s%s.idl",dir,filename);
outfp = fopen(file2,"w");
fprintf(outfp,"CATCH,error_status\n");
fprintf(outfp,"IF (error_status NE 0) THEN EXIT\n");
fprintf(outfp,"CD,'%s'\n",dir);
fprintf(outfp,"RESTORE,'waveplot.sav'\n");
fprintf(outfp,".run waveplot\n");
fprintf(outfp,"waveplot,'%s','%s'\n",filename,time_str);
fprintf(outfp,"EXIT\n");
fclose(outfp);
/* run IDL batch file */
sprintf(command,"/usr/local/rsi/idl/bin/idl %s",file2);
system(command);
/* read in HTML & dump to browser */
sprintf(file2,"%s%s.html",dir,filename);
infp = fopen(file2,"r");
(void) fgets(data,sizeof(data),infp);
while (!feof(infp)) {
printf("%s\n",data);
(void) fgets(data,sizeof(data),infp);
}
fclose(infp);
/* automatically remove data & gif files more than 4 days old... */
sprintf(command,"find %sout -name 'wave_*' -mtime +4 -exec rm {} \\;",dir);
system(command);
}
|
the_stack_data/43888408.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <ctype.h>
#define SIZE_MD5 35
#define L_HASEL_MD5 441
#define L_SLOW_SLOWNIK 10000
#define DL_SLOWA 32
#define NUM_THREADS 6
struct dane_wejsciowe
{
char tab_MD5_wej[L_HASEL_MD5][SIZE_MD5];
char* tab_slow_wej[L_SLOW_SLOWNIK];
}dane_wej;
struct dane_wyjsciowe
{
pthread_mutex_t mutex;
pthread_cond_t cond;
int nready;
int licznik;
char tab_MD5_wyj[100][33];
char tab_slow_wyj[100][64];
} dane_wyj = {PTHREAD_MUTEX_INITIALIZER,
PTHREAD_COND_INITIALIZER};
int praca=1;
int count=0;
char tab_prawdy[L_SLOW_SLOWNIK]={0};
pthread_mutex_t mutex_1;
pthread_t threads[NUM_THREADS];
FILE *slownik;
FILE *hasla_MD5;
void sighandler(int signum);
void koduj_MD5(char *slowo_pobrane, char kod[33]);
void *watek_1();
void *watek_2();
void *watek_3();
void *watek_4();
void *watek_5();
void *konsument(void *dane);
//############## MAIN ##############
int main(int argc, char *argv[])
{
//############## ZMIENNE ##############
char tab_pom[DL_SLOWA];
char tab_pom2[SIZE_MD5];
char *tmp_wsk;
char *tmp_wsk2;
char *znak="\0";
dane_wyj.licznik=0;
//######################################
signal(SIGHUP, sighandler);//FUNKCJA OBSLUGUJACA SYGNAL
//############## SPRAWDZENIE LICZBY ARGUMENTOW ##############
if(argc!=3)
{
puts("Podano niewlasciwa liczbe argumentow.");
puts("Poprawna liczba to dwa argumenty.");
}
//######################################
//############## PROBA OTWARCIA PLIKOW SLOWNIK I KODY MD5
if((slownik=fopen(argv[1],"r"))==NULL)
{
printf("Nie mozna otworzyc pliku %s\n",argv[1]);
exit(EXIT_FAILURE);
}
if((hasla_MD5=fopen(argv[2],"r"))==NULL)
{
printf("Nie mozna otworzyc pliku %s\n",argv[2]);
exit(EXIT_FAILURE);
}
//######################################
//############## POBIERANIE LISTY HASEL MD5 ##############
for (int index = 0; index < L_HASEL_MD5; index++)
{
tmp_wsk=fgets (tab_pom2, SIZE_MD5, hasla_MD5); // czytamy ze standardowego wejścia
strncpy(dane_wej.tab_MD5_wej[index],tab_pom2,SIZE_MD5);
strcpy(dane_wej.tab_MD5_wej[index]+32,znak);
if (tmp_wsk != NULL)
{
if (feof (hasla_MD5))
printf ("\n%d koniec pliku\n", index);
}
else
printf ("\n%d blad odczytu\n", index);
}
//######################################
//############## POBIERANIE LISTY SLOW ZE SLOWNIKA ##############
for (int index = 0; index < L_SLOW_SLOWNIK ; index++)
{
tmp_wsk=fgets (tab_pom,DL_SLOWA,slownik); //ODCZYT Z PLIKU SLOWNIK DO TAB_POM
dane_wej.tab_slow_wej[index]=(char *)calloc(strlen(tab_pom),sizeof(char)); //PRZYPISANIE ODPOWIEDNIEJ ILOSCI PAMIECI
strncpy(dane_wej.tab_slow_wej[index],tab_pom,strlen(tab_pom)-1);// PRZYPISANIE SLOWA Z PLIKU DO DANYCH WEJSCIOWYCH
if (tmp_wsk != NULL)
{
if (feof (slownik))
printf ("\n%d koniec pliku\n", index);
}
else
printf ("\n%d blad odczytu\n", index);
}
//######################################
//######################################
/* Initialize mutex and condition variable objects */
pthread_mutex_init(&dane_wyj.mutex, NULL);
pthread_mutex_init(&mutex_1, NULL);
pthread_cond_init (&dane_wyj.cond, NULL);
/* For portability, explicitly create threads in a joinable state */
pthread_create(&threads[0], NULL, konsument, (void *) &dane_wyj);
pthread_create(&threads[1], NULL, watek_1, NULL);
pthread_create(&threads[2], NULL, watek_2, NULL);
pthread_create(&threads[3], NULL, watek_3, NULL);
pthread_create(&threads[4], NULL, watek_4, NULL);
pthread_create(&threads[5], NULL, watek_5, NULL);
//############## CZYSZCZENIE PAMIECI I ZAMYKANIE PLIKOW ##############
fclose(slownik);
fclose(hasla_MD5);
//pthread_attr_destroy(&attr);
pthread_mutex_destroy(&mutex_1);
pthread_mutex_destroy(&dane_wyj.mutex);
pthread_cond_destroy(&dane_wyj.cond);
pthread_exit (NULL);
for(int i=0; i<L_SLOW_SLOWNIK;i++)
{
free(dane_wej.tab_slow_wej[i]);
}
//######################################
return 0;
}
//######################################################
//FUNKCJA TWORZACA KOD MD5
void koduj_MD5(char *slowo_pobrane, char kod[33])
{
EVP_MD_CTX *mdctx; //tworzenie struktury ktora zawiera rodzaj kodowania
const EVP_MD *md; //przechowuje skrot kodowania MD5 MD4 i to co zawiera openssl
unsigned char md_value[32];
unsigned int md_len;
char znak_pom;
char tab_pom[3];
md = EVP_get_digestbyname("MD5");
mdctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(mdctx, md, NULL);//ustawia kontekst kodowania w strukturze mdctx, na MD5 lub inne dostepne w openssl
EVP_DigestUpdate(mdctx, slowo_pobrane, strlen(slowo_pobrane));// tutaj odbywa się kodowanie naszego tekstu do wybranego klucza (MD5)
EVP_DigestFinal_ex(mdctx, md_value, &md_len);//pobiera wartosc mdctx i zapisuje do wartosci md_value, md_len tutaj zostaje zapisana liczba bajtow, ktore zostaly zapisane
EVP_MD_CTX_free(mdctx);//zwalnia pamiec zajmowana przez strukture mdctx
for (int i = 0; i < md_len; i++)
{
znak_pom=(char)md_value[i];
sprintf(kod+2*i,"%02X",znak_pom & 0xff);
}
}
//######################################
//WATEK DODAJACY NA POCZATEK SLOWA LICZBE
void *watek_1()
{
char znak_pom;
char tab_pom[3];
char kod_md5[33];
char *nowe_slowo;
int sprawdzenie=1;
while(praca)
{
for(int a=0; a<L_SLOW_SLOWNIK; a++)
{
for(int c=0; c<1000; c++)
{
if(c<10)
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+2, sizeof(char));
else if(c<100)
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+3, sizeof(char));
else
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+4, sizeof(char));
sprintf(nowe_slowo,"%d",c);
strcat(nowe_slowo, dane_wej.tab_slow_wej[a]);
koduj_MD5(nowe_slowo, kod_md5);
//printf("Wygenerowane slowo %s, kod to: %s .\n",nowe_slowo,kod_md5);
for(int b=0; b<L_HASEL_MD5; b++)
{
sprawdzenie=strncmp(kod_md5, dane_wej.tab_MD5_wej[b],32);//ZWRACA 0 JESLI LANCUCHY SA TAKIE SAME
if(sprawdzenie==0&&tab_prawdy[a]==0)
{
pthread_mutex_lock(&dane_wyj.mutex); //POCZATEK SEKCJI KRYTYCZNEJ
strncpy(dane_wyj.tab_slow_wyj[dane_wyj.licznik],nowe_slowo,strlen(nowe_slowo));
strncpy(dane_wyj.tab_MD5_wyj[dane_wyj.licznik],kod_md5, strlen(kod_md5));
//printf("Znaleziono slowo: %s i kod: %s .\n",dane_wyj.tab_slow_wyj[dane_wyj.licznik], dane_wyj.tab_MD5_wyj[dane_wyj.licznik]);
puts("Watek pierwszy wykryl slowo.");
dane_wyj.nready++;
tab_prawdy[a]=1;
pthread_cond_signal(&dane_wyj.cond);
pthread_mutex_unlock(&dane_wyj.mutex);//KONIEC SEKCJI KRYTYCZNEJ
sleep(1);
break;
}
}
free(nowe_slowo);
}
}
}
pthread_exit(NULL);
}
//######################################
//WATEK SPRAWDZAJACY SLOWA ZE SLOWNIKA BEZ ZADNYCH ZMIAN
void *watek_2()
{
char znak_pom;
char tab_pom[3];
char kod_md5[33];
int sprawdzenie=1;
char *nowe_slowo;
while(praca)
{
for(int a=0; a<L_SLOW_SLOWNIK; a++)
{
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+3, sizeof(char));
strcpy(nowe_slowo, dane_wej.tab_slow_wej[a]);
koduj_MD5(nowe_slowo, kod_md5);
for(int b=0; b<L_HASEL_MD5; b++)
{
sprawdzenie=strncmp(kod_md5, dane_wej.tab_MD5_wej[b],32);
if(sprawdzenie==0&&tab_prawdy[a]==0)
{
pthread_mutex_lock(&dane_wyj.mutex); //POCZATEK SEKCJI KRYTYCZNEJ
strncpy(dane_wyj.tab_slow_wyj[dane_wyj.licznik],nowe_slowo,strlen(nowe_slowo));
strncpy(dane_wyj.tab_MD5_wyj[dane_wyj.licznik],kod_md5, strlen(kod_md5));
//printf("Znaleziono slowo: %s i kod: %s .\n",dane_wyj.tab_slow_wyj[dane_wyj.licznik], dane_wyj.tab_MD5_wyj[dane_wyj.licznik]);
puts("Watek drugi wykryl slowo.");
dane_wyj.nready++;
tab_prawdy[a]=1;
pthread_cond_signal(&dane_wyj.cond);
pthread_mutex_unlock(&dane_wyj.mutex);//KONIEC SEKCJI KRYTYCZNEJ
sleep(1);
break;
}
}
}
}
pthread_exit(NULL);
}
//######################################
//WATEK DODAJACY LICZBE NA KONIEC SLOWA
void *watek_3()
{
char znak_pom;
char tab_pom[4];
char kod_md5[33];
char *nowe_slowo;
int sprawdzenie=1;
while(praca)
{
for(int a=0; a<L_SLOW_SLOWNIK; a++)
{
for(int c=0; c<1000; c++)
{
if(c<10)
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+2, sizeof(char));
else if(c<100)
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+3, sizeof(char));
else
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+4, sizeof(char));
sprintf(nowe_slowo,"%s",dane_wej.tab_slow_wej[a]);
sprintf(tab_pom,"%d",c);
strcat(nowe_slowo,tab_pom);
koduj_MD5(nowe_slowo, kod_md5);
//printf("Wygenerowane slowo %s, kod to: %s .\n",nowe_slowo,kod_md5);
for(int b=0; b<L_HASEL_MD5; b++)
{
sprawdzenie=strncmp(kod_md5, dane_wej.tab_MD5_wej[b],32);//ZWRACA 0 JESLI LANCUCHY SA TAKIE SAME
if(sprawdzenie==0&&tab_prawdy[a]==0)
{
pthread_mutex_lock(&dane_wyj.mutex); //POCZATEK SEKCJI KRYTYCZNEJ
strncpy(dane_wyj.tab_slow_wyj[dane_wyj.licznik],nowe_slowo,strlen(nowe_slowo));
strncpy(dane_wyj.tab_MD5_wyj[dane_wyj.licznik],kod_md5, strlen(kod_md5));
//printf("Znaleziono slowo: %s i kod: %s .\n",dane_wyj.tab_slow_wyj[dane_wyj.licznik], dane_wyj.tab_MD5_wyj[dane_wyj.licznik]);
dane_wyj.nready++;
tab_prawdy[a]=1;
puts("Watek trzeci wykryl slowo.");
pthread_cond_signal(&dane_wyj.cond);
pthread_mutex_unlock(&dane_wyj.mutex);//KONIEC SEKCJI KRYTYCZNEJ
sleep(1);
break;
}
}
free(nowe_slowo);
}
}
}
pthread_exit(NULL);
}
//######################################
//WATEK ZAMIENIAJACY MALE LITERY NA DUZE
void *watek_4()
{
char znak_pom;
char tab_pom[4];
char kod_md5[33];
char *nowe_slowo;
int sprawdzenie=1;
while(praca)
{
for(int a=0; a<L_SLOW_SLOWNIK; a++)
{
nowe_slowo=(char*)calloc(strlen(dane_wej.tab_slow_wej[a])+1, sizeof(char));
sprintf(nowe_slowo,"%s",dane_wej.tab_slow_wej[a]);
strcat(nowe_slowo,tab_pom);
for(int c=0; c<strlen(nowe_slowo); c++)
{
nowe_slowo[c]=toupper(nowe_slowo[c]);
}
koduj_MD5(nowe_slowo, kod_md5);
//printf("Wygenerowane slowo %s, kod to: %s .\n",nowe_slowo,kod_md5);
for(int b=0; b<L_HASEL_MD5; b++)
{
sprawdzenie=strncmp(kod_md5, dane_wej.tab_MD5_wej[b],32);//ZWRACA 0 JESLI LANCUCHY SA TAKIE SAME
if(sprawdzenie==0&&tab_prawdy[a]==0)
{
pthread_mutex_lock(&dane_wyj.mutex); //POCZATEK SEKCJI KRYTYCZNEJ
strncpy(dane_wyj.tab_slow_wyj[dane_wyj.licznik],nowe_slowo,strlen(nowe_slowo));
strncpy(dane_wyj.tab_MD5_wyj[dane_wyj.licznik],kod_md5, strlen(kod_md5));
//printf("Znaleziono slowo: %s i kod: %s .\n",dane_wyj.tab_slow_wyj[dane_wyj.licznik], dane_wyj.tab_MD5_wyj[dane_wyj.licznik]);
dane_wyj.nready++;
tab_prawdy[a]=1;
puts("Watek czwarty wykryl slowo.");
pthread_cond_signal(&dane_wyj.cond);
pthread_mutex_unlock(&dane_wyj.mutex);//KONIEC SEKCJI KRYTYCZNEJ
sleep(1);
break;
}
}
free(nowe_slowo);
}
}
pthread_exit(NULL);
}
//######################################
//WATEK LACZACY DWA SLOWA, POMIEDZY KTORYMI ZNAJDUJE SIE LICZBA
void *watek_5()
{
char znak_pom;
char tab_pom[3];
char kod_md5[33];
char *nowe_slowo;
int sprawdzenie=1;
int dl_slowa;
while(praca)
{
for(int a=0; a<L_SLOW_SLOWNIK; a++)
{
for(int c=0; c<1000; c++)
{
for(int d=0; d<L_SLOW_SLOWNIK;d++)
{
if(c<10)
dl_slowa=strlen(dane_wej.tab_slow_wej[a])+2+strlen(dane_wej.tab_slow_wej[d]);
else if(c<100)
dl_slowa=strlen(dane_wej.tab_slow_wej[a])+3+strlen(dane_wej.tab_slow_wej[d]);
else
dl_slowa=strlen(dane_wej.tab_slow_wej[a])+4+strlen(dane_wej.tab_slow_wej[d]);
nowe_slowo=(char*)calloc(dl_slowa, sizeof(char));
strcat(nowe_slowo,dane_wej.tab_slow_wej[a]);
sprintf(tab_pom,"%d",c);
strcat(nowe_slowo,tab_pom);
strcat(nowe_slowo,dane_wej.tab_slow_wej[d]);
koduj_MD5(nowe_slowo, kod_md5);
//printf("Wygenerowane slowo %s, kod to: %s .\n",nowe_slowo,kod_md5);
//sleep(1);
for(int b=0; b<L_HASEL_MD5; b++)
{
sprawdzenie=strncmp(kod_md5, dane_wej.tab_MD5_wej[b],32);//ZWRACA 0 JESLI LANCUCHY SA TAKIE SAME
//printf("Wygenerowane slowo %s, kod to: %s, kod ze slownika to: %s, warosc sprawdzenia to %d.\n",nowe_slowo,kod_md5,dane_wej.tab_MD5_wej[b],sprawdzenie);
//sleep(1);
if(sprawdzenie==0)
{
pthread_mutex_lock(&dane_wyj.mutex); //POCZATEK SEKCJI KRYTYCZNEJ
strncpy(dane_wyj.tab_slow_wyj[dane_wyj.licznik],nowe_slowo,strlen(nowe_slowo));
strncpy(dane_wyj.tab_MD5_wyj[dane_wyj.licznik],kod_md5, strlen(kod_md5));
//printf("Znaleziono slowo: %s i kod: %s .\n",dane_wyj.tab_slow_wyj[dane_wyj.licznik], dane_wyj.tab_MD5_wyj[dane_wyj.licznik]);
puts("Watek piaty wykryl slowo.");
dane_wyj.nready++;
//tab_prawdy[a]=1;
pthread_cond_signal(&dane_wyj.cond);
pthread_mutex_unlock(&dane_wyj.mutex);//KONIEC SEKCJI KRYTYCZNEJ
sleep(1);
break;
}
}
free(nowe_slowo);
}
}
}
}
pthread_exit(NULL);
}
//######################################
//WATEK KONSUMENTA ODPOWIEDZIAILNY ZA WYPISANIE ZNALEZIONEGO SLOWA NA BIEZACO
void *konsument(void *dane)
{
struct dane_wyjsciowe* info = (struct dane_wyjsciowe*)dane;
while (praca)
{
pthread_mutex_lock(&dane_wyj.mutex);
//printf("Konsument czeka na odebranie znalezionego hasla.\n");
while(dane_wyj.nready==0)
pthread_cond_wait(&dane_wyj.cond, &dane_wyj.mutex);
printf("Znalezionym haslem nr. %d jest: %s o kodzie %s .\n",dane_wyj.licznik,dane_wyj.tab_slow_wyj[dane_wyj.licznik],dane_wyj.tab_MD5_wyj[dane_wyj.licznik]);
dane_wyj.nready--;
dane_wyj.licznik++;
pthread_mutex_unlock(&dane_wyj.mutex);
}
pthread_exit(NULL);
}
//######################################
//PRZECHWYTYWANIE SYGNALU I WYPISYWANIE WSZYSTKICH ZNALEZIONYCH SLOW
void sighandler(int signum)
{
printf("Przechwycono sygnal %d, konczenie pracy.\n", signum);
praca=0;
for(int i=0; i<dane_wyj.licznik; i++)
{
printf("Wartosc licznika to: %d, slowo to: %s, a kod to: %s\n", i, dane_wyj.tab_slow_wyj[i],dane_wyj.tab_MD5_wyj[i] );
}
for(int i=0; i<L_SLOW_SLOWNIK;i++)
{
free(dane_wej.tab_slow_wej[i]);
}
fclose(slownik);
fclose(hasla_MD5);
exit(1);
}
//######################################
|
the_stack_data/154518.c | // UNSAFE
int foo(int n){
int i = 1;
int sum = 0;
int product = 1;
if (i<=n){
sum = sum + i;
product = product * i;
i = i + 1;
}
return sum;
// POST: sum = {0,1}
}
extern sys_call(int x);
int main(){
int x,y,z;
if (y > 0)
y = y + 1; // y > 0
else{
y = foo(y) - 1; // {-1,0}
y = foo(5) + 5; // {5,6}
// POST: y > 0
}
z = sys_call(y);
_TRACER_abort(z <= 0);
return z ;
}
|
the_stack_data/72012372.c | /*
======================================================================
Name : DB_SQLite.c
Author : morris
Version :
Copyright : Your copyright notice
Description : sqlite3数据库的使用
======================================================================
1. 如何改善并发性能:一个数据库文件存放一张表
2. 动态数据类型:
NULL:空值
INTEGER:带符号的整形
REAL:浮点数,存储为8字节的IEEE浮点数
TEXT:字符串文本
BLOB:二进制对象
3. 每个数据库都保存在一个二进制文件中
4. 通过数据库级共享锁实现事务处理,并支持原子操作。当多个进程同时向同一数据库写入文件的时候,
只有一个进程能够抢占到数据库资源
======================================================================
连接SQLite数据库,不存在则创建
int sqlite3_open(
const char *filename, //必须是UTF8编码的数据库文件名
sqlite3 **ppDb //SQLite数据库标识符指针
);
成功返回0,出错返回错误代码
======================================================================
关闭已经打开的数据库
int sqlite3_close(sqlite3* db);
======================================================================
执行SQL语句(用来完成增删改的操作)
int sqlite3_exec(
sqlite3* db, //数据库标识符
const char *sql, //SQL命令字符串
int (*callback)(void*,int,char**,char**),//回调函数,当sqlite3_exec函数
//执行成功时将调用回调函数
void *, //第一个回调参数
char **errmsg //将错误信息写到此指针指向的地址
);
======================================================================
执行SQL查询语句
int SQLITE_STDCALL sqlite3_get_table(
sqlite3 *db, //数据库标识符
const char *zSql, //SQL查询语句
char ***pazResult, //查询结果
int *pnRow, //查询结果的行数
int *pnColumn, //查询结果的列数
char **pzErrmsg //错误信息
);
*/
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DB_FILE_NAME "consume.sqlite"
#define TABLE_MAIN_MENU "main_menu"
#define TABLE_SUB_MENU "sub_menu"
#define TABLE_RECORD "record"
#define ID "id"
#define MAIN_MENU_ID "main_id"
#define SUB_MENU_ID "sub_id"
#define MAIN_MENU_NAME "main_menu_name"
#define SUB_MENU_NAME "sub_menu_name"
#define FEE "fee"
#define TIME "time"
#define ROWID "rowid"
#define BUFF_SIZE (32)
static void execSQL(sqlite3* db, const char* cmd) {
int ret = 0;
char* errMsg = NULL;
char** result;
int row, col;
int i;
if (db) {
/* 增删改语句 */
if (strncasecmp(cmd, "select", 6)) {
ret = sqlite3_exec(db, cmd, NULL, NULL, &errMsg);
if (ret != SQLITE_OK) {
printf("exec sql command failed:%d-%s\r\n", ret, errMsg);
} else {
printf("exec sql command success\r\n");
}
}
/* 查询语句 */
else {
ret = sqlite3_get_table(db, cmd, &result, &row, &col, &errMsg);
if (ret != SQLITE_OK) {
printf("exec sql command failed:%d-%s\r\n", ret, errMsg);
} else {
printf("exec sql command success\r\n");
for (i = 0; i < (row + 1) * col; i++) {
printf("%s%s", result[i],
((i + 1) % col) ? "\t\t" : "\r\n");
}
}
/* 释放结果所占用的内存空间 */
sqlite3_free_table(result);
}
}
sqlite3_free(errMsg);
}
int main(int argc, char **argv) {
sqlite3* db = NULL;
char sqlCmd[256];
char buf[BUFF_SIZE];
int action_select;
int main_select;
int sub_select;
int query_select;
double fee;
int ret;
/* 1. 连接数据库 */
ret = sqlite3_open_v2(DB_FILE_NAME, &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (ret) {
printf("open sqlite3 database failed:%s\r\n", sqlite3_errmsg(db));
exit(1);
} else {
printf("open a sqlite3 database success\r\n");
}
/* 2. 创建数据表 */
/**
* 主菜单数据表 副菜单数据表 消费记录数据表
* id 主菜单名 id 主菜单ID 副菜单名 副菜单ID 消费金额 消费时间
*/
/* 主菜单数据表 */
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd,
"create table %s(\
%s integer primary key not null,\
%s text)",
TABLE_MAIN_MENU, ID, MAIN_MENU_NAME);
execSQL(db, sqlCmd);
/* 副菜单数据表*/
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd,
"create table %s(\
%s integer primary key not null,\
%s integer not null,\
%s text);",
TABLE_SUB_MENU, ID, MAIN_MENU_ID, SUB_MENU_NAME);
execSQL(db, sqlCmd);
/* 消费记录数据表 */
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd,
"create table %s(\
%s integer not null,\
%s real default 10.0 check(%s < 20000),\
%s text);",
TABLE_RECORD, SUB_MENU_ID, FEE, FEE, TIME);
execSQL(db, sqlCmd);
/* 3. 插入数据 */
/* 插入主菜单数据表 */
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(1,'饮食');", TABLE_MAIN_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(2,'交通');", TABLE_MAIN_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(3,'医疗');", TABLE_MAIN_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(4,'水电');", TABLE_MAIN_MENU);
execSQL(db, sqlCmd);
/* 插入副菜单数据表 */
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(1,1,'早饭');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(2,1,'午饭');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(3,1,'晚饭');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(4,1,'点心');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(5,2,'公交');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(6,2,'打的');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(7,2,'火车');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(8,2,'飞机');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(9,3,'药费');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(10,3,'挂水费');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(11,3,'手术费');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(12,3,'住院费');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(13,4,'水');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(14,4,'电');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(15,4,'煤气');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(16,4,'暖气');", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
while (1) {
printf(
"可进行的操作选项有:\r\n1. 插入数据\r\n2. 修改数据\r\n3. 删除数据\r\n4. 查询数据\r\n5. 删除数据表\r\n");
printf("请选择你要进行的操作('q' to quit):");
if (fgets(buf, BUFF_SIZE, stdin)) {
if (strncasecmp(buf, "q", 1) == 0) {
break;
}
action_select = atoi(buf);
} else {
break;
}
/* 插入数据操作 */
if (action_select == 1) {
printf("********主菜单********\r\n");
printf("1. 饮食\r\n2. 交通\r\n3. 医疗\r\n4. 水电\r\n请输入:");
if (fgets(buf, BUFF_SIZE, stdin)) {
main_select = atoi(buf);
switch (main_select) {
case 1:
printf("********副菜单********\r\n");
printf("1. 早饭\r\n2. 午饭\r\n3. 晚饭\r\n4. 点心\r\n请输入:");
break;
case 2:
printf("********副菜单********\r\n");
printf("1. 公交\r\n2. 打的\r\n3. 火车\r\n4. 飞机\r\n请输入:");
break;
case 3:
printf("********副菜单********\r\n");
printf("1. 药费\r\n2. 挂水费\r\n3. 手术费\r\n4. 住院费\r\n请输入:");
break;
case 4:
printf("********副菜单********\r\n");
printf("1. 水\r\n2. 电\r\n3. 煤气\r\n4. 暖气\r\n请输入:");
break;
}
if (fgets(buf, BUFF_SIZE, stdin)) {
sub_select = atoi(buf);
} else {
break;
}
printf("请输入消费金额:");
if (fgets(buf, BUFF_SIZE, stdin)) {
fee = atof(buf);
}
} else {
break;
}
/* 插入消费记录数据表 */
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "insert into %s values(%d,%f,datetime('now'));",
TABLE_RECORD, sub_select, fee);
execSQL(db, sqlCmd);
}
/* 4. 修改数据 */
/* 测试:将第一条消费的金额改为10 */
else if (action_select == 2) {
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "update %s set %s=10 where %s=1;", TABLE_RECORD,
FEE, ROWID);
execSQL(db, sqlCmd);
}
/* 5. 删除数据 */
/* 测试:将第一条消费记录删除 */
else if (action_select == 3) {
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "delete from %s where %s=1;", TABLE_RECORD, ROWID);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "vacuum %s;", TABLE_RECORD);
execSQL(db, sqlCmd);
}
/* 6. 查询数据 */
else if (action_select == 4) {
printf(
"可供查询的信息有:\r\n1. 所有消费历史记录\r\n2. 某一天消费记录\r\n3. 消费总和\r\n 请输入序号: ");
if (fgets(buf, BUFF_SIZE, stdin)) {
query_select = atoi(buf);
} else {
break;
}
switch (query_select) {
case 1:
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd,
"select * from %s left outer join %s on %s.%s=%s.%s order by %s desc;",
TABLE_SUB_MENU, TABLE_RECORD, TABLE_SUB_MENU, ID,
TABLE_RECORD, SUB_MENU_ID, TIME);
execSQL(db, sqlCmd);
break;
case 2:
printf("请输入日期(格式1900-01-01):");
scanf("%s", buf);
getchar(); //将回车符从输入缓存中删掉
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "select * from %s where %s like '%%%s%%';",
TABLE_RECORD, TIME, buf);
execSQL(db, sqlCmd);
break;
case 3:
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "select sum(%s),%s from %s group by %s;",
FEE, TIME, TABLE_RECORD, TIME);
execSQL(db, sqlCmd);
break;
default:
break;
}
}
/* 7. 删除表 */
else if (action_select == 5) {
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "drop table %s", TABLE_MAIN_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "drop table %s", TABLE_SUB_MENU);
execSQL(db, sqlCmd);
memset(sqlCmd, 0, sizeof(sqlCmd));
sprintf(sqlCmd, "drop table %s", TABLE_RECORD);
execSQL(db, sqlCmd);
}
}
/* 8. 断开数据库连接 */
ret = sqlite3_close(db);
if (ret) {
printf("close sqlite3 database failed:%s\r\n", sqlite3_errmsg(db));
exit(1);
} else {
printf("close sqlite3 database success.\r\n");
}
return 0;
}
|
the_stack_data/35963.c | #include<stdio.h>
#include<assert.h>
int main()
{
int rt, rs;
int achi, acli;
int dsp;
int acho, aclo;
int resulth, resultl;
int resdsp;
achi = 0x00000005;
acli = 0x0000B4CB;
rs = 0xFF060000;
rt = 0xCB000000;
resulth = 0x00000005;
resultl = 0x006838CB;
__asm
("mthi %2, $ac1\n\t"
"mtlo %3, $ac1\n\t"
"maq_s.w.phl $ac1, %4, %5\n\t"
"mfhi %0, $ac1\n\t"
"mflo %1, $ac1\n\t"
: "=r"(acho), "=r"(aclo)
: "r"(achi), "r"(acli), "r"(rs), "r"(rt)
);
assert(resulth == acho);
assert(resultl == aclo);
achi = 0x00000006;
acli = 0x0000B4CB;
rs = 0x80000000;
rt = 0x80000000;
resulth = 0x00000006;
resultl = 0x8000B4CA;
resdsp = 1;
__asm
("mthi %3, $ac1\n\t"
"mtlo %4, $ac1\n\t"
"maq_s.w.phl $ac1, %5, %6\n\t"
"mfhi %0, $ac1\n\t"
"mflo %1, $ac1\n\t"
"rddsp %2\n\t"
: "=r"(acho), "=r"(aclo), "=r"(dsp)
: "r"(achi), "r"(acli), "r"(rs), "r"(rt)
);
assert(resulth == acho);
assert(resultl == aclo);
assert(((dsp >> 17) & 0x01) == resdsp);
return 0;
}
|
the_stack_data/68887425.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swapint64.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jwinthei <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/01 18:19:28 by jwinthei #+# #+# */
/* Updated: 2020/12/01 18:25:05 by jwinthei ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdint.h>
uint64_t ft_swapint64(uint64_t x)
{
return (((x & 0x00000000000000FFULL) << 56) |\
((x & 0x000000000000FF00ULL) << 40) |\
((x & 0x0000000000FF0000ULL) << 24) |\
((x & 0x00000000FF000000ULL) << 8) |\
((x & 0x000000FF00000000ULL) >> 8) |\
((x & 0x0000FF0000000000ULL) >> 24) |\
((x & 0x00FF000000000000ULL) >> 40) |\
((x & 0xFF00000000000000ULL) >> 56));
}
|
the_stack_data/51699717.c | #define type short
type glob0, glob1;
#define E0 ((type *)10000000)
#define reg0 r0
#define indreg0 (*p0)
#define imm0 22
#define limm0 ((type)&glob0)
#define adr0 (*E0)
#define adrreg0 (p0[10000000])
#define adrx0 (E0[x0])
#define regx0 (p0[x0])
#define E1 ((type *)(11111111 & ~(__alignof__ (type) - 1)))
#define reg1 r1
#define indreg1 (*p1)
#define imm1 33
#define limm1 ((type)&glob1)
#define adr1 (*E1)
#define adrreg1 (p1[1111111/4])
#define adrx1 (E1[x1])
#define regx1 (p1[x1])
reg0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= reg1) return 1; else return 0;}
reg0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= indreg1) return 1; else return 0;}
reg0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= imm1) return 1; else return 0;}
reg0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= limm1) return 1; else return 0;}
reg0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= adr1) return 1; else return 0;}
reg0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= adrreg1) return 1; else return 0;}
reg0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= adrx1) return 1; else return 0;}
reg0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (reg0 <= regx1) return 1; else return 0;}
indreg0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= reg1) return 1; else return 0;}
indreg0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= indreg1) return 1; else return 0;}
indreg0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= imm1) return 1; else return 0;}
indreg0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= limm1) return 1; else return 0;}
indreg0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= adr1) return 1; else return 0;}
indreg0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= adrreg1) return 1; else return 0;}
indreg0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= adrx1) return 1; else return 0;}
indreg0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (indreg0 <= regx1) return 1; else return 0;}
imm0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= reg1) return 1; else return 0;}
imm0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= indreg1) return 1; else return 0;}
imm0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= imm1) return 1; else return 0;}
imm0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= limm1) return 1; else return 0;}
imm0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= adr1) return 1; else return 0;}
imm0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= adrreg1) return 1; else return 0;}
imm0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= adrx1) return 1; else return 0;}
imm0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (imm0 <= regx1) return 1; else return 0;}
limm0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= reg1) return 1; else return 0;}
limm0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= indreg1) return 1; else return 0;}
limm0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= imm1) return 1; else return 0;}
limm0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= limm1) return 1; else return 0;}
limm0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= adr1) return 1; else return 0;}
limm0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= adrreg1) return 1; else return 0;}
limm0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= adrx1) return 1; else return 0;}
limm0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (limm0 <= regx1) return 1; else return 0;}
adr0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= reg1) return 1; else return 0;}
adr0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= indreg1) return 1; else return 0;}
adr0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= imm1) return 1; else return 0;}
adr0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= limm1) return 1; else return 0;}
adr0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= adr1) return 1; else return 0;}
adr0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= adrreg1) return 1; else return 0;}
adr0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= adrx1) return 1; else return 0;}
adr0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adr0 <= regx1) return 1; else return 0;}
adrreg0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= reg1) return 1; else return 0;}
adrreg0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= indreg1) return 1; else return 0;}
adrreg0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= imm1) return 1; else return 0;}
adrreg0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= limm1) return 1; else return 0;}
adrreg0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= adr1) return 1; else return 0;}
adrreg0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= adrreg1) return 1; else return 0;}
adrreg0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= adrx1) return 1; else return 0;}
adrreg0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrreg0 <= regx1) return 1; else return 0;}
adrx0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= reg1) return 1; else return 0;}
adrx0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= indreg1) return 1; else return 0;}
adrx0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= imm1) return 1; else return 0;}
adrx0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= limm1) return 1; else return 0;}
adrx0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= adr1) return 1; else return 0;}
adrx0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= adrreg1) return 1; else return 0;}
adrx0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= adrx1) return 1; else return 0;}
adrx0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (adrx0 <= regx1) return 1; else return 0;}
regx0reg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= reg1) return 1; else return 0;}
regx0indreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= indreg1) return 1; else return 0;}
regx0imm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= imm1) return 1; else return 0;}
regx0limm1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= limm1) return 1; else return 0;}
regx0adr1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= adr1) return 1; else return 0;}
regx0adrreg1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= adrreg1) return 1; else return 0;}
regx0adrx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= adrx1) return 1; else return 0;}
regx0regx1 (r0, r1, x0, x1, p0, p1)
type r0, r1; type *p0, *p1;
{if (regx0 <= regx1) return 1; else return 0;}
|
the_stack_data/1245020.c | //
// gets.c
//
#include "stdio.h"
///
/// Consume a line of text from stdin. Newline is discarded, per C99.
///
/// This is subject to buffer overrun problems. In general, use fgets()
/// instead of gets() for safety reasons.
///
/// @param buffer -- the buffer in which to place the incoming characters
///
/// @return a pointer to the input buffer
///
char*
gets(char *buffer)
{
if (buffer)
{
char* b = buffer;
int c; // Type-promotion to catch possible EOF
// Read characters until the first newline
c = getchar();
while((c != '\n') && (c != EOF))
{
*b = (char)(c);
b++;
c = getchar();
}
// Discard the newline + terminate the string
*b = '\0';
}
return(buffer);
}
|
the_stack_data/1103211.c | #include <assert.h>
#include <stdio.h>
#include <string.h>
// nota: el guion bajo es porque "union" es una palabra reservada del lenguaje
size_t union_(const int a[], size_t na, const int b[], size_t nb, int r[]) {
if (na == 0 || nb == 0)
return 0;
if (a[0] == b[0]) {
r[0] = a[0];
return 1 + union_(a + 1, na - 1, b + 1, nb - 1, r + 1);
} else if (a[0] < b[0]) {
r[0] = a[0];
return 1 + union_(a + 1, na - 1, b, nb, r + 1);
} else {
r[0] = b[0];
return 1 + union_(a, na, b + 1, nb - 1, r + 1);
}
}
int main(void) {
int a[] = {1, 3, 5, 7};
int b[] = {2, 3, 6, 7};
int r[8];
size_t nr = union_(a, 4, b, 4, r);
assert(nr == 6);
int r_esperado[] = {1, 2, 3, 5, 6, 7};
assert(memcmp(r, r_esperado, 6 * sizeof(int)) == 0);
printf("%s: OK\n", __FILE__);
return 0;
}
// 17 min |
the_stack_data/95137.c | /* { dg-do compile } */
/* { dg-require-weak "" } */
/* { dg-options "-fno-common" } */
/* { dg-skip-if "" { *-*-mingw* } { "*" } { "" } } */
/* NVPTX's definition of weak looks different to normal. */
/* { dg-skip-if "" { nvptx-*-* } { "*" } { "" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?a" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?b" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?c" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?d" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?e" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?g" } } */
/* { dg-final { scan-assembler-not "weak\[^ \t\]*\[ \t\]_?i" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?j" } } */
#pragma weak a
int a;
int b;
#pragma weak b
#pragma weak c
extern int c;
int c;
extern int d;
#pragma weak d
int d;
#pragma weak e
void e(void) { }
#if 0
/* This permutation is illegal. */
void f(void) { }
#pragma weak f
#endif
#pragma weak g
int g = 1;
#if 0
/* This permutation is illegal. */
int h = 1;
#pragma weak h
#endif
#pragma weak i
extern int i;
#pragma weak j
extern int j;
int use_j() { return j; }
|
the_stack_data/393858.c | #include <stdio.h>
int main(){
int a[10],i,n,s;
printf("Enter no of elements:");
scanf("%d",&n);
printf("Element to search:");
scanf("%d",&s);
for(i=0;i<n;i++){
printf("Enter no%d:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
if(s==a[i]){
printf("%d is present at location: %d",s,i);
}
}
}
|
the_stack_data/433711.c | /*++
Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
crc32.c
Abstract:
CalcuateCrc32 routine.
Modified to avoid EFI dependencies for mkgpt
--*/
#include <stdlib.h>
#include <stdint.h>
uint32_t mCrcTable[256] = {
0x00000000,
0x77073096,
0xEE0E612C,
0x990951BA,
0x076DC419,
0x706AF48F,
0xE963A535,
0x9E6495A3,
0x0EDB8832,
0x79DCB8A4,
0xE0D5E91E,
0x97D2D988,
0x09B64C2B,
0x7EB17CBD,
0xE7B82D07,
0x90BF1D91,
0x1DB71064,
0x6AB020F2,
0xF3B97148,
0x84BE41DE,
0x1ADAD47D,
0x6DDDE4EB,
0xF4D4B551,
0x83D385C7,
0x136C9856,
0x646BA8C0,
0xFD62F97A,
0x8A65C9EC,
0x14015C4F,
0x63066CD9,
0xFA0F3D63,
0x8D080DF5,
0x3B6E20C8,
0x4C69105E,
0xD56041E4,
0xA2677172,
0x3C03E4D1,
0x4B04D447,
0xD20D85FD,
0xA50AB56B,
0x35B5A8FA,
0x42B2986C,
0xDBBBC9D6,
0xACBCF940,
0x32D86CE3,
0x45DF5C75,
0xDCD60DCF,
0xABD13D59,
0x26D930AC,
0x51DE003A,
0xC8D75180,
0xBFD06116,
0x21B4F4B5,
0x56B3C423,
0xCFBA9599,
0xB8BDA50F,
0x2802B89E,
0x5F058808,
0xC60CD9B2,
0xB10BE924,
0x2F6F7C87,
0x58684C11,
0xC1611DAB,
0xB6662D3D,
0x76DC4190,
0x01DB7106,
0x98D220BC,
0xEFD5102A,
0x71B18589,
0x06B6B51F,
0x9FBFE4A5,
0xE8B8D433,
0x7807C9A2,
0x0F00F934,
0x9609A88E,
0xE10E9818,
0x7F6A0DBB,
0x086D3D2D,
0x91646C97,
0xE6635C01,
0x6B6B51F4,
0x1C6C6162,
0x856530D8,
0xF262004E,
0x6C0695ED,
0x1B01A57B,
0x8208F4C1,
0xF50FC457,
0x65B0D9C6,
0x12B7E950,
0x8BBEB8EA,
0xFCB9887C,
0x62DD1DDF,
0x15DA2D49,
0x8CD37CF3,
0xFBD44C65,
0x4DB26158,
0x3AB551CE,
0xA3BC0074,
0xD4BB30E2,
0x4ADFA541,
0x3DD895D7,
0xA4D1C46D,
0xD3D6F4FB,
0x4369E96A,
0x346ED9FC,
0xAD678846,
0xDA60B8D0,
0x44042D73,
0x33031DE5,
0xAA0A4C5F,
0xDD0D7CC9,
0x5005713C,
0x270241AA,
0xBE0B1010,
0xC90C2086,
0x5768B525,
0x206F85B3,
0xB966D409,
0xCE61E49F,
0x5EDEF90E,
0x29D9C998,
0xB0D09822,
0xC7D7A8B4,
0x59B33D17,
0x2EB40D81,
0xB7BD5C3B,
0xC0BA6CAD,
0xEDB88320,
0x9ABFB3B6,
0x03B6E20C,
0x74B1D29A,
0xEAD54739,
0x9DD277AF,
0x04DB2615,
0x73DC1683,
0xE3630B12,
0x94643B84,
0x0D6D6A3E,
0x7A6A5AA8,
0xE40ECF0B,
0x9309FF9D,
0x0A00AE27,
0x7D079EB1,
0xF00F9344,
0x8708A3D2,
0x1E01F268,
0x6906C2FE,
0xF762575D,
0x806567CB,
0x196C3671,
0x6E6B06E7,
0xFED41B76,
0x89D32BE0,
0x10DA7A5A,
0x67DD4ACC,
0xF9B9DF6F,
0x8EBEEFF9,
0x17B7BE43,
0x60B08ED5,
0xD6D6A3E8,
0xA1D1937E,
0x38D8C2C4,
0x4FDFF252,
0xD1BB67F1,
0xA6BC5767,
0x3FB506DD,
0x48B2364B,
0xD80D2BDA,
0xAF0A1B4C,
0x36034AF6,
0x41047A60,
0xDF60EFC3,
0xA867DF55,
0x316E8EEF,
0x4669BE79,
0xCB61B38C,
0xBC66831A,
0x256FD2A0,
0x5268E236,
0xCC0C7795,
0xBB0B4703,
0x220216B9,
0x5505262F,
0xC5BA3BBE,
0xB2BD0B28,
0x2BB45A92,
0x5CB36A04,
0xC2D7FFA7,
0xB5D0CF31,
0x2CD99E8B,
0x5BDEAE1D,
0x9B64C2B0,
0xEC63F226,
0x756AA39C,
0x026D930A,
0x9C0906A9,
0xEB0E363F,
0x72076785,
0x05005713,
0x95BF4A82,
0xE2B87A14,
0x7BB12BAE,
0x0CB61B38,
0x92D28E9B,
0xE5D5BE0D,
0x7CDCEFB7,
0x0BDBDF21,
0x86D3D2D4,
0xF1D4E242,
0x68DDB3F8,
0x1FDA836E,
0x81BE16CD,
0xF6B9265B,
0x6FB077E1,
0x18B74777,
0x88085AE6,
0xFF0F6A70,
0x66063BCA,
0x11010B5C,
0x8F659EFF,
0xF862AE69,
0x616BFFD3,
0x166CCF45,
0xA00AE278,
0xD70DD2EE,
0x4E048354,
0x3903B3C2,
0xA7672661,
0xD06016F7,
0x4969474D,
0x3E6E77DB,
0xAED16A4A,
0xD9D65ADC,
0x40DF0B66,
0x37D83BF0,
0xA9BCAE53,
0xDEBB9EC5,
0x47B2CF7F,
0x30B5FFE9,
0xBDBDF21C,
0xCABAC28A,
0x53B39330,
0x24B4A3A6,
0xBAD03605,
0xCDD70693,
0x54DE5729,
0x23D967BF,
0xB3667A2E,
0xC4614AB8,
0x5D681B02,
0x2A6F2B94,
0xB40BBE37,
0xC30C8EA1,
0x5A05DF1B,
0x2D02EF8D
};
int
CalculateCrc32 (
uint8_t *Data,
size_t DataSize,
uint32_t *CrcOut
)
/*++
Routine Description:
The CalculateCrc32 routine.
Arguments:
Data - The buffer contaning the data to be processed
DataSize - The size of data to be processed
CrcOut - A pointer to the caller allocated UINT32 that on
contains the CRC32 checksum of Data
Returns:
EFI_SUCCESS - Calculation is successful.
EFI_INVALID_PARAMETER - Data / CrcOut = NULL, or DataSize = 0
--*/
{
uint32_t Crc;
size_t Index;
uint8_t *Ptr;
if ((DataSize == 0) || (Data == NULL) || (CrcOut == NULL)) {
return -1;
}
Crc = 0xffffffff;
for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {
Crc = (Crc >> 8) ^ mCrcTable[(uint8_t) Crc ^ *Ptr];
}
*CrcOut = Crc ^ 0xffffffff;
return 0;
}
|
the_stack_data/43886796.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anajmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/05 12:20:26 by anajmi #+# #+# */
/* Updated: 2021/07/05 14:58:49 by anajmi ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcat(char *dest, char *src)
{
unsigned int i;
unsigned int a;
i = 0;
while (dest[i] != '\0')
i++;
a = 0;
while (src[a] != '\0')
{
dest[i + a] = src[a];
a++;
}
dest[i + a] = '\0';
return (dest);
}
|
the_stack_data/220455716.c | #include <stdlib.h>
int main()
{
malloc(1024);
malloc(1024 * 32);
malloc(1024 * 1024);
malloc(1024 * 1024 * 16);
malloc(1024 * 1024 * 128);
show_alloc_mem();
return (0);
}
|
the_stack_data/161080575.c | /* basic_design_zynq_hw_exerciser.c
*
* This program demonstrates the basic capabilities of a Zynq platform
* communicating with two axi_gpio peripherals (from the IP catalog) that
* are implemented as hardware in the PL.
*
* NOTE: THE GPIO THAT IS CONTAINED IN THE PS IS NOT BEING USED
*
* One of the GPIO's is configured as an 8 bit output driving 8 LED's.
* The other GPIO is configured as a three input device being driven
* from push buttons.
*
* The program functions in a forever loop, monitoring the input push
* buttons. The three buttons are UP, DOWN, and STOP that directly
* control the a binary counting pattern on the LED's.
*
* This application is written to either, use the Standalone library
* or be compiled as a Linux application. Either flow is supported in
* the SDK programming development. The default compilation is using
* the Standalone library. To compile this application as a Linux
* application, add to the properties of the associated application
* project, a #define of a symbol named "LINUX_APP". Select properties and
* C/C++ Build => Settings => ARM Linux gcc compiler => Symbols,
* adding a -D LINUX_APP to the gcc compiler tool command line.
*
* The hardware (axi_gpio) physical device pinout in the PL may vary
* with the target evaluation board being used. This variation is
* typically manifested in the constraints file which determines
* device pin locations for the actual pin numbers used for the LED's
* and pushbuttons. Other variations in the hardware may be needed to
* accommodate the fact that varying numbers of pushbutton inputs or
* LED output actually exist.
*
* The goal is that this application can be targeted to multiple
* hardware Zynq platforms (or configurations) either as a Standalone
* or Linux application.
*
* THE FOLLOWING HARDWARE PLATFORMS ARE DEFINED
* ZC702 BOARD
* LED's - Eight LED's, DS15-DS22, located towards the center of the
* board from the SD card slot
* Push Buttons - Only two buttons are use, located adjacent to the LED's
* UP - SW7
* DOWN - SW5
* STOP - Pressing both, SW5 and SW7, at the same time provides a STOP
* (Due to a lack of pushbuttons accessible by PL pins, hardware
* in the PL was added to emulate a third button)
*
* ZC702 BOARD WITH CE (Customer Education) FMC CARD IN FMC1 SLOT
* LED's - Eight LED's, LD0-LD7, located between slide switches and LCD display
* Push Buttons - Rosetta buttons located on CE FMC card,
* UP - BTN3 - West
* DOWN - BTN0 - Center
* STOP - BTN1 - East
*
* ******************************************************************************************************************
*
*
* basic_design_exerciser
* Ver.: 1.0 6/1/2012 WK/LR
*
* This code generates an LED pattern for the 8 bit LED array present on the ZC702 board. It must have
* one of several symbols defined:
* hardware_test - infinite loop, long delays for LEDs so user can visually recognize what is happening, uses standalone drivers
* profiler_test - finite loop for gprof, short delays so profiler doesn't report all the activity being in the wait_loop function, uses standalone drivers
* CSP_test - infinite loop, short delays so multiple datum can be captured with the Analyzer, uses standalone drivers
* LINUX_APP - infinite loop, long delays for LEDs so user can visually recogize what is happening, uses Linux drivers
*
* ******************************************************************************************************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
// Stuff needed for Linux DEVMEM access
#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE - 1)
#define TRUE 1
#define FALSE 1
typedef int u32; // add this compatibility for int's between Linux and Standalone
// Linux pointers to GPIO's in PL hardware
void *mapped_led_dev_base; // Address of LED GPIO
void *mapped_button_dev_base; // Address of Push Button GPIO
void *mapped_base; // Address of device memory window, it is global for visibility in main to unmount device memory
int memfd; // device memory handle for Linux device to memory mapping, it is global for visibility in main to unmount device memory
// Linux application needs gpio base address and register offsets, Standalone application gets it from xparameters.h
#define GPIO_BUTTON_BASE_ADDRESS 0x41240000
#define GPIO_LED_BASE_ADDRESS 0x40000000
#define GPIO_DATA_OFFSET 0x0000
#define GPIO_DIRECTION_OFFSET 0x0004
// access the serial output
#define print printf
// constants
#define LED_DELAY_NORMAL 5000000
#define LED_DELAY_PROFILE 2
#define BUTTON_CHANNEL 1
#define LED_CHANNEL 1
#define ALL_OUTPUTS 0
#define ALL_INPUTS 0xffffffff
// function prototypes (functions defined in this file after the main)
void *Linux_GPIO_initialize(int gpio_base_address, int direction, int first_call);
// for the hardware exerciser...
void hardware_exerciser(); // name of routine follows common 'C' language convention
#define PI (double)3.141592653 // approximation of PI
void do_sine_sample(int sample); // takes sample and calls other routines to get results to LEDs, serial port
void doBarGraph(int value, int style); // name of routine follows common Java language convention (legal for C)
void driveBarGraph(int value); // actually selects which LEDs are active and makes peripheral call
#define CYLON 1
#define BAR 2
#define BINARY 3
double sine(double angle_in_radians);
double factorial(int final_term);
char *itoa(int value, char *string, int radix);
char *strcat (char *destination, const char *source);
void delay_loop(long int delay_count);
int buttons_get_state(void);
void LEDs_driver(int pattern);
int LED_delay_max; // maximum value to delay to for the LED wait loop
/*
* ***********************************************************
*/
int main() {
// local variable
int mode = 0; // used to check that one of the environment variables used
// let the user know that we're starting
print("---basic_design_zynq Exerciser---\n\r");
//***** initialize the GPIOs *****
// For Linux access memory mapped GPIO without kernel driver and initialize.
// The function returns a pointer address to the associated GPIO and sets the GPIO direction
mapped_led_dev_base = Linux_GPIO_initialize(GPIO_LED_BASE_ADDRESS, ALL_OUTPUTS, TRUE);
mapped_button_dev_base = Linux_GPIO_initialize(GPIO_BUTTON_BASE_ADDRESS, ALL_INPUTS, FALSE);
// determine the use of this software - are we exercising the hardware or doing the profiling exercise?
#ifdef hardware_test
LED_delay_max = LED_DELAY_NORMAL;
print("running the hardware test...\n\r");
mode = 1;
#endif
#ifdef profiler_test
LED_delay_max = LED_DELAY_PROFILE;
print("running the profiler code...\n\r");
mode = 2;
#endif
#ifdef CSP_test
LED_delay_max = LED_DELAY_PROFILE;
print("running the CSP analyzer code...\n\r");
mode = 3;
#endif
LED_delay_max = LED_DELAY_NORMAL;
print("running the Linux app...\n\r");
mode = 4;
// check to see that one or the other mode was selected, otherwise warn the user and abort
if (mode != 0) {
hardware_exerciser(); // read switches, detect changes, increment/decrement counter, display count on LEDs...
} else {
print("you must set the symbol \"hardware_test\", \"profiler_test\", \"CSP_test\", or \"LINUX_APP\" in the compiler settings!\n\r");
}
print("---Exiting main---\n\r"); // never reached...
// unmap the memory used for the GPIO device before exiting
// Linux only, but will never be reached
// It is a good programming practice to always release the memory space the device was accessing
// Since the Standalone drivers can always access memory, this sort of functionality is not needed
if (munmap(mapped_base, MAP_SIZE) == -1) {
printf("Can't unmap memory from user space.\n");
exit(0);
}
printf("Memory Unmapped\n");
close(memfd);
return 0;
}
/*
* ************** Hardware Exerciser Code *************************
*/
#define UP 0
#define LEFT 0
#define DOWN 1
#define RIGHT 1
#define STOP 2
#define ONE_PERIOD 128
#define AMPLITUDE 256
#define ABS(a) (((a) < 0) ? -(a) : (a))
/*
* ****************************************************************************************************
* HARDWARE EXERCISER CODE
* ****************************************************************************************************
*/
void hardware_exerciser() {
// local variables
u32 last_button_state = 0;
u32 current_button_state = 0;
u32 button_difference = 0;
int count_direction = UP;
int sample = 0;
int keep_running = 1;
int profile_iteration_count = 500000; // used only in profile mode
// deliberate infinite loop
while (keep_running) {
// read current switch configuration
current_button_state = buttons_get_state();
button_difference = (current_button_state ^ last_button_state) & current_button_state; // detect a change and that it has been pushed (not released)
if (button_difference != 0) {
// has anything changed based on the buttons?
if (button_difference & 0x04) { print("Stop counting..."); count_direction = STOP; }
else if (button_difference & 0x02) { print("Counting down..."); count_direction = DOWN; }
else if (button_difference & 0x01) { print("Counting up..."); count_direction = UP; }
}
last_button_state = current_button_state; // update the button status to prevent runaway button action
// compute the next sample number (period of 256)
if (count_direction = UP) { sample++; sample %= ONE_PERIOD; }
else if (count_direction = DOWN) { sample--; if (sample < -1) sample = ONE_PERIOD-1; }
else { /* no change */}
// do the math and drive the LEDs
do_sine_sample(sample);
// wait loop - caution - delay loops like this are removed when optimization is turned on!
delay_loop(LED_delay_max); // delay for a slower display
// if this is the profiler mode, we need to quit after a while
#ifdef profiler_test
keep_running = profile_iteration_count--;
#endif
}
}
// compute sine, drive LEDs and serial port
// 0 < sample < ONE_PERIOD
void do_sine_sample(int location_in_period) {
// local variables
double radian_equivalent;
int sine_value;
char buf[32],*message, *strValue; // used in hardware_test mode only
// do the computation of this point for sine
radian_equivalent = (double)(location_in_period)/(double)(ONE_PERIOD) * 3.1415927f * 2.0; // one full circle
sine_value = (int)((double)(AMPLITUDE) * sine(radian_equivalent) / 2); // this is +/- (i.e. range -1:1 converted to 0:1), so...
sine_value += AMPLITUDE/2; // bias this up so that 0 is in the middle
// drive the bar graph display
driveBarGraph(sine_value);
#ifdef hardware_test
// display the value on the serial port and wait a bit for the LEDs/user to catch up - but only in hardware test mode
// no output will be present in the profiler_test
strValue = itoa(sine_value,buf,10);
message = strcat(strValue,"...");
xil_printf(message);
#endif
}
/*
* sine(angle in radians)
*
* where: 0 <= angle in radians <= 2 PI
*
* does Taylor series expansion (4 terms) to compute sine
* taylor series good only for small angles - use reflection technique to determine value outside of Q1
* Q2 = PI - x
* Q3 = - (x - PI)
* Q4 = - (2PI - x)
*
* Note: this algorithm deliberately uses a slow, iterative way to compute factorials. The faster way:
* int factorial[] = { 1, 1, 2, 6, 24, 120, 720, 5040 }; // the "fast" way to do it - precompute for the # of terms you need, then it's just a memory lookup
* result = angle_in_radians - X3/factorial[3] + X5/factorial[5] - X7/factorial[7];
*
*/
double sine(double angle_in_radians) {
double X2;
double X3;
double X5;
double X7;
double result;
int quadrant = 1; // begin by assuming Q1
// determine quadrant and reflect horizontally (if necessary)
if (angle_in_radians > 3*PI/2) { // in Q4?
quadrant = 4; // remember for later
angle_in_radians = 2 * PI - angle_in_radians; // do horizontal (x) reflection, y reflection done later
} else if (angle_in_radians > PI) { // in Q3?
quadrant = 3; // remember for later
angle_in_radians = angle_in_radians - PI; // no x reflection, y reflection done later
} else if (angle_in_radians > PI/2) { // in Q2?
quadrant = 2; // remember for later
angle_in_radians = PI - angle_in_radians; // do horizontal (x) reflection
}
// compute powers of angle_in_radians
X2 = angle_in_radians * angle_in_radians;
X3 = X2 * angle_in_radians;
X5 = X3 * X2;
X7 = X5 * X2;
// compute the sine approximation to 4 places for Q1
result = angle_in_radians - X3/factorial(3) + X5/factorial(5) - X7/factorial(7);
// do vertical reflection for Q3 and Q4
if (quadrant > 2) {
result *= -1; // flip the Q1/Q2 result
}
return result;
}
double factorial(int final_term) {
double result = 1.0;
int term;
for (term=2; term<=final_term; term++) {
result *= term;
}
return result;
}
/******************************************************************************************************
* LINUX GPIO INITIALIZATION
* This function performs two operations:
* 1) Opens a device to memory window in Linux so a GPIO that exists at a physical address is mapped
* to a fixed logical address. This logical address is returned by the function.
* 2) Initialize the GPIO for either input or output mode.
*
* INPUT PARAMETERS:
* gpio_base_address - physical hardware base address of GPIO, you have to get this from XML file
* direction - 32 bits indicating direction for each bit; 0 - output; 1 - input
* first_call - boolean indicating that this is first call to function. The first time and only the first
* time should the Linux device memory mapping service be mounted. Call for subsequent
* gpio mapping this should be set to FALSE (0).
*
* RETURNS:
* mapped_dev_base - memory pointer to the GPIO that was specified by the gpio_base_address
*******************************************************************************************************/
void *Linux_GPIO_initialize(int gpio_base_address, int direction, int first_call)
{
void *mapped_dev_base;
off_t dev_base = gpio_base_address;
// Linux service to directly access PL hardware as memory without using a device driver
// The memory mapping to device service should only be called once
if (first_call) {
memfd = open("/dev/mem", O_RDWR | O_SYNC);
if (memfd == -1) {
printf("Can't open /dev/mem.\n");
exit(0);
}
printf("/dev/mem opened.\n");
}
// Map one page of memory into user space such that the device is in that page, but it may not
// be at the start of the page.
mapped_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, dev_base & ~MAP_MASK);
if (mapped_base == (void *) -1) {
printf("Can't map the memory to user space for LED GPIO.\n");
exit(0);
}
printf("LED GPIO memory mapped at address %p.\n", mapped_base);
// Get the address of the device in user space which will be an offset from the base
// that was mapped as memory is mapped at the start of a page
mapped_dev_base = mapped_base + (dev_base & MAP_MASK);
// Slight delay for Linux memory access problem
usleep(50);
// write to the direction GPIO direction register to set as all inputs or outputs
*((volatile unsigned long *) (mapped_dev_base + GPIO_DIRECTION_OFFSET)) = direction;
return mapped_dev_base;
}
/*
* driveBarGraph(12 bit value)
*
* calls doBarGraph. this routine determines which of the 8 possible bins/bars should be illuminated
*
*/
#define NUMBER_OF_LEDS 8
void driveBarGraph(int value) {
char buf[32]; // used in hardware test mode
double bin_range = (AMPLITUDE) / (NUMBER_OF_LEDS); // how large is each bin?
int nBars = (int)((double)value / bin_range); // how many bars should be lit?
#ifdef hardware_test
// only print the diagnostic text in hardware_test mode
xil_printf(itoa(nBars,buf,10)); print("\n\r");
#endif
// turn on the proper LEDs based on the # of bars and the style
doBarGraph(nBars,CYLON); //
}
/*
* doBarGraph(device, value to display, style in which to display
*
*
* example value = 5, style shown below: LED 7 6 5 4 3 2 1 0
* Style: BAR - solid up to value - - * * * * * * * = on, - = off
* CYLON - single bar at value - - * - - - - -
* BINARY- binary representation of value - - - - - * - *
* other - displays error pattern - * - * - * - *
*
*/
void doBarGraph(int value, int style) {
if (style == BAR) {
switch (value) {
case 0: LEDs_driver(0x00); break;
case 1: LEDs_driver(0x01); break;
case 2: LEDs_driver(0x03); break;
case 3: LEDs_driver(0x07); break;
case 4: LEDs_driver(0x0f); break;
case 5: LEDs_driver(0x1f); break;
case 6: LEDs_driver(0x3f); break;
case 7: LEDs_driver(0x7f); break;
case 8: LEDs_driver(0xff); break;
default: LEDs_driver(0x55); // non-contiguous pattern indicates error
}
} else if (style == CYLON) {
switch (value) {
case 0: LEDs_driver(0x01); break;
case 1: LEDs_driver(0x02); break;
case 2: LEDs_driver(0x04); break;
case 3: LEDs_driver(0x08); break;
case 4: LEDs_driver(0x10); break;
case 5: LEDs_driver(0x20); break;
case 6: LEDs_driver(0x40); break;
case 7: LEDs_driver(0x80); break;
default: LEDs_driver(0x55); // non-contiguous pattern indicates error
}
} else if (style == BINARY) {
LEDs_driver(value); // simple binary value to display
} else {
LEDs_driver(0x69); // different error pattern
}
}
/*
* *** buttons_get_state()
*
* returns an integer representing the value of the buttons
* 0 - no buttons pressed
* 1 - left/down button pressed
* 2 - right/up button pressed
* 3 - both buttons pressed
*
* this function is coded this way so that it is clear what the Linux vs. Standalone/bare-metal are.
*/
int buttons_get_state()
{
// local variables
int current_button_state = 0;
// Linux read of gpio, notice that it accesses the data register of the GPIO as a memory location, no device driver needed!
current_button_state = *((volatile unsigned long *) (mapped_button_dev_base + GPIO_DATA_OFFSET));
}
/*
* *** LEDs_driver(led image (int))
*
* sets the LED channel 1 device to the passed value
*
* this function is coded this way so that it is clear what the Linux vs. Standalone/bare-metal are.
*/
void LEDs_driver(int led_image)
{
// Linux write to gpio, by writing to a memory address of the gpio data register, no device driver needed!
*((volatile unsigned long *) (mapped_led_dev_base + GPIO_DATA_OFFSET)) = led_image;
}
/*
* *** delay_loop(int delay_count)
*
* finite loop which causes a simple delay
* could have been also performed, more accurately, using the usleep() function
*
*/
void delay_loop(long int count)
{
int i;
for (i=0; i<count; i++);
}
/*
* *** itoa
*
* converts an integer into a string - also found in the C library
*
*/
char *itoa(int value, char *string, int radix)
{
char tmp[33];
char *tp = tmp;
int i;
unsigned v;
int sign;
char *sp;
if (radix > 36 || radix <= 1) { string = "radix out of range 1..36"; return 0; }
sign = (radix == 10 && value < 0);
if (sign) { v = -value; }
else { v = (unsigned)value; }
while (v || tp == tmp) {
i = v % radix;
v = v / radix;
if (i < 10) { *tp++ = i+'0'; }
else { *tp++ = i + 'a' - 10; }
}
if (string == 0) {
string = (char *)malloc((tp-tmp)+sign+1);
// xil_printf("call to malloc() made\n\r");
}
sp = string;
if (sign) { *sp++ = '-'; }
while (tp > tmp) { *sp++ = *--tp; }
*sp = 0;
return string;
}
/*
* *** strcat
*
* returns the concatonation of two strings
*
* may also be found in string.h
*
*/
char * strcat ( char * destination, const char * source ){
char *d = destination;
while (*d) ++d;
while ((*d++ = *source++) != '\0') ;
return (destination);
}
|
the_stack_data/167332020.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#define EC256_CERT "./certs/ECC_Prime256_Certs/serv_cert.pem"
#define EC256_PRIV "./certs/ECC_Prime256_Certs/serv_key_unencrypted.pem"
#define ED25519_CERT "certs/ED25519/rootcert.pem"
#define ED25519_PRIV "certs/ED25519/rootkey.pem"
#define MAX_SIGN_SIZE 256
typedef struct speed_timer_st {
int secs;
long finish_time;
}SPEED_TIMER;
void init_timer(SPEED_TIMER *timer, int secs)
{
timer->finish_time = time(NULL) + secs;
}
int is_timer_expired(SPEED_TIMER *timer)
{
if (timer->finish_time < time(NULL)) {
return 1;
}
return 0;
}
BIO *convert_file_2_bio(const char *file_name)
{
BIO *bio_file;
if ((bio_file = BIO_new(BIO_s_file())) == NULL) {
printf("BIO new failed\n");
goto err;
}
if (BIO_read_filename(bio_file, file_name) <=0) {
printf("BIO read failed\n");
goto err;
}
return bio_file;
err:
BIO_free(bio_file);
return NULL;
}
EVP_PKEY *get_pub_key(const char *pub_file)
{
EVP_PKEY *pub_key = NULL;
X509 *cert = NULL;
BIO *bio_file;
if ((bio_file = convert_file_2_bio(pub_file)) == NULL)
goto err;
if ((cert = PEM_read_bio_X509(bio_file, NULL, NULL, NULL)) == NULL) {
printf("Cert read failed\n");
goto err;
}
if ((pub_key = X509_get_pubkey(cert)) == NULL) {
printf("Get pub key failed\n");
goto err;
}
printf("Decoded cert[%s] successfully\n", pub_file);
err:
BIO_free(bio_file);
X509_free(cert);
return pub_key;
}
EVP_PKEY *get_priv_key(const char *priv_file)
{
EVP_PKEY *priv_key = NULL;
BIO *bio_file;
if ((bio_file = convert_file_2_bio(priv_file)) == NULL)
goto err;
if ((priv_key = PEM_read_bio_PrivateKey(bio_file, NULL, NULL, NULL)) == NULL) {
printf("Decode priv key failed\n");
goto err;
}
printf("Decoded priv key[%s] successfully\n", priv_file);
err:
BIO_free(bio_file);
return priv_key;
}
int do_sign_verify(int alg_nid, const char *cert_file, const char *priv_file, int secs)
{
EVP_MD_CTX *ed_sign_ctx = NULL, *ed_veri_ctx = NULL;
EVP_PKEY *ed_pub_key;
EVP_PKEY *ed_priv_key = NULL;
int ret_val = -1;
uint8_t sign[MAX_SIGN_SIZE] = {0};
size_t sign_len;
char data[] = "abcdefghijabcdefghij";
long finish_time;
uint32_t count = 0;
if ((ed_pub_key = get_pub_key(cert_file)) == NULL)
goto err;
if ((ed_priv_key = get_priv_key(priv_file)) == NULL)
goto err;
if ((ed_sign_ctx = EVP_MD_CTX_new()) == NULL
|| EVP_DigestSignInit(ed_sign_ctx, NULL, NULL, NULL, ed_priv_key) != 1) {
printf("MD Sign ctx init failed\n");
goto err;
}
if ((ed_veri_ctx = EVP_MD_CTX_new()) == NULL
|| EVP_DigestVerifyInit(ed_veri_ctx, NULL, NULL, NULL, ed_pub_key) != 1) {
printf("MD Verify Ctx init failed\n");
goto err;
}
finish_time = time(NULL) + secs;
while (1) {
sign_len = sizeof(sign);
if (finish_time < time(NULL)) {
break;
}
if (EVP_DigestSign(ed_sign_ctx, sign, &sign_len, (uint8_t *)data, strlen(data)) != 1) {
printf("ED Sign failed\n");
goto err;
}
if (EVP_DigestVerify(ed_veri_ctx, sign, sign_len, (uint8_t *)data, strlen(data)) != 1) {
printf("MD Verify failed\n");
goto err;
}
printf("*");
count++;
}
printf("\n%s Sign/Verify of data %zu bytes performed %u operations in %d secs\n",
OBJ_nid2sn(alg_nid), sizeof(data), count, secs);
printf("%s Sign/Verify of data %zu bytes performed %u operations/secs\n",
OBJ_nid2sn(alg_nid), sizeof(data), count/secs);
ret_val = 0;
err:
EVP_PKEY_free(ed_pub_key);
EVP_PKEY_free(ed_priv_key);
EVP_MD_CTX_free(ed_sign_ctx);
EVP_MD_CTX_free(ed_veri_ctx);
return ret_val;
}
#define RAND_SIZE 224
int do_rand(int secs)
{
long finish_time;
uint8_t data[RAND_SIZE] = {0};
uint32_t count = 0;
int ret;
finish_time = time(NULL) + secs;
while (1) {
if (finish_time < time(NULL)) {
break;
}
if ((ret = RAND_priv_bytes(data, sizeof(data))) != 1) {
printf("RAND_priv_bytes failed\n");
goto err;
}
printf("*");
count++;
}
printf("\nRand of data %zu bytes performed %u operations in %d secs\n",
sizeof(data), count, secs);
printf("Rand of data %zu bytes performed %u operations/secs\n",
sizeof(data), count/secs);
printf("Rand generation performance is %f MB/secs\n",
(((float)(sizeof(data) * count)) / secs) / (1024 * 1024));
return 0;
err:
return -1;
}
#define ENC_DATA_SIZE 256
#define ENC_BLOCK_SIZE 16
#define ENC_KEY_SIZE 16
/* SPEED_CONF_SYM's mode */
#define SPEED_SYM_ALG_MODE_WITH_DEC 0x00000001UL
#define SPEED_SYM_ALG_MODE_UPDATE_AND_FINAL 0x00000002UL
typedef struct speed_conf_sym_st {
int nid;
const char *nid_str;
uint32_t cli_mode; /* Enabled based on CLI args */
uint32_t op_mode; /* Current mode which is in operation */
const char *op_str; /* String for logging purpose */
}SPEED_CONF_SYM;
typedef struct speed_conf_st {
SPEED_CONF_SYM sym;
int secs;
}SPEED_CONF;
void *get_ciph_ctx_ossl(SPEED_CONF *conf, uint8_t *key, uint32_t key_size,
uint8_t *iv, uint32_t iv_size, int enc)
{
const EVP_CIPHER *ciph;
EVP_CIPHER_CTX *ciph_ctx = NULL;
if ((ciph = EVP_get_cipherbynid(conf->sym.nid)) == NULL) {
printf("Get cipher by nid failed\n");
return NULL;
}
if ((ciph_ctx = EVP_CIPHER_CTX_new()) == NULL) {
printf("Cipher ctx new failed\n");
goto err;
}
if ((enc == 1) && EVP_EncryptInit_ex(ciph_ctx, ciph, NULL, key, iv) != 1) {
printf("Enc Cipher ctx init failed\n");
goto err;
} else if ((enc == 0) && EVP_DecryptInit_ex(ciph_ctx, ciph, NULL, key, iv) != 1) {
printf("Dec Cipher ctx init failed\n");
goto err;
}
return ciph_ctx;
err:
EVP_CIPHER_CTX_free(ciph_ctx);
return NULL;
}
void *get_ciph_ctx(SPEED_CONF *conf, uint8_t *key, uint32_t key_size,
uint8_t *iv, uint32_t iv_size, int enc)
{
return get_ciph_ctx_ossl(conf, key, key_size, iv, iv_size, enc);
}
void free_ciph_ctx_ossl(SPEED_CONF *conf, void *enc_ctx, void *dec_ctx)
{
EVP_CIPHER_CTX_free(enc_ctx);
EVP_CIPHER_CTX_free(dec_ctx);
}
void free_ciph_ctx(SPEED_CONF *conf, void *enc_ctx, void *dec_ctx)
{
free_ciph_ctx_ossl(conf, enc_ctx, dec_ctx);
}
int do_enc_ossl(void *ciph_ctx, uint8_t *out, uint32_t out_size, uint8_t *in, uint32_t in_size)
{
if (EVP_Cipher(ciph_ctx, out, in, in_size) < 1) { //TODO Raise PR to openssl master
printf("EVP_Cipher failed\n");
return -1;
}
return 0;
}
int do_enc(void *ciph_ctx, uint8_t *out, uint32_t out_size, uint8_t *in, uint32_t in_size)
{
return do_enc_ossl(ciph_ctx, out, out_size, in, in_size);
}
int do_dec_ossl(void *ciph_ctx, uint8_t *out, uint32_t out_size, uint8_t *ciph, uint32_t ciph_size)
{
if (EVP_Cipher(ciph_ctx, out, ciph, ciph_size) < 1) { //TODO Here too
printf("EVP_Cipher failed\n");
return -1;
}
return 0;
}
int do_dec(void *ciph_ctx, uint8_t *ciph, uint32_t ciph_size, uint8_t *plain, uint32_t plain_size)
{
uint8_t out[ENC_DATA_SIZE + ENC_BLOCK_SIZE] = {0};
if (do_dec_ossl(ciph_ctx, out, sizeof(out), ciph, ciph_size) != 0) {
printf("EVP_Cipher decrypt failed\n");
return -1;
}
if (memcmp(out, plain, plain_size) != 0) {
printf("Decrypted data not matching!!!\n");
return -1;
}
return 0;
}
int speed_sym_alg_op(SPEED_CONF *conf)
{
SPEED_TIMER timer = {0};
uint8_t data[ENC_DATA_SIZE] = {0};
uint8_t out[ENC_DATA_SIZE + ENC_BLOCK_SIZE] = {0};
uint8_t key[ENC_KEY_SIZE] = {0};
uint8_t iv[ENC_KEY_SIZE] = {0};
void *enc_ctx = NULL;
void *dec_ctx = NULL;
uint32_t count = 0;
int ret_val = -1;
printf("Performing %s %s... ", conf->sym.nid_str, conf->sym.op_str);
fflush(stdout);
memset(data, 'a', sizeof(data));
init_timer(&timer, conf->secs);
while (1) {
if (is_timer_expired(&timer) == 1) {
break;
}
if ((enc_ctx = get_ciph_ctx(conf, key, sizeof(key), iv, sizeof(iv), 1)) == NULL) {
return -1;
}
if (do_enc(enc_ctx, out, sizeof(out), data, sizeof(data)) != 0) {
goto err;
}
if (conf->sym.op_mode & SPEED_SYM_ALG_MODE_WITH_DEC) {
if ((dec_ctx = get_ciph_ctx(conf, key, sizeof(key), iv, sizeof(iv), 0)) == NULL) {
return -1;
}
if (do_dec(dec_ctx, out, sizeof(out), data, sizeof(data)) != 0) {
goto err;
}
}
free_ciph_ctx(conf, enc_ctx, dec_ctx);
enc_ctx = dec_ctx = NULL;
count++;
}
printf("[%f MB/secs]\n", (((float)(sizeof(data) * count)) / conf->secs) / (1024 * 1024));
ret_val = 0;
err:
free_ciph_ctx(conf, enc_ctx, dec_ctx);
return ret_val;
}
int speed_sym_alg(SPEED_CONF *conf)
{
conf->sym.op_mode = SPEED_SYM_ALG_MODE_WITH_DEC;
conf->sym.op_str = "Sym Enc/Dec";
return speed_sym_alg_op(conf);
}
int main(int argc, char *argv[])
{
SPEED_CONF conf;
memset(&conf, 0, sizeof(conf));
//return do_sign_verify(NID_ED25519, ED25519_CERT, ED25519_PRIV, secs);
//return do_sign_verify(NID_X9_62_prime256v1, EC256_CERT, EC256_PRIV, secs);
//return do_rand(secs);
conf.secs = 10;
conf.sym.nid = NID_aes_128_cbc;
conf.sym.nid_str = "AES_128_CBC";
return speed_sym_alg(&conf);
}
|
the_stack_data/198579874.c | /*
* lab005 - sync disk writes to a file.
*
* 21-May-2015 Brendan Gregg Created this.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const char *datafile = "lab005.data";
#define BUFSIZE (8 * 1024)
#define FILESIZE (10 * 1024 * 1024)
void
write_log(int fd)
{
char buf[BUFSIZE];
int i;
for (;;) {
for (i = 0; i < FILESIZE / BUFSIZE; i++) {
if (write(fd, buf, BUFSIZE) < 0) {
printf("ERROR: write error.\n");
exit(2);
}
}
if (lseek(fd, 0, SEEK_SET) < 0) {
printf("ERROR: seek() failed.\n");
exit(3);
}
}
}
int
main()
{
int fd;
if ((fd = open(datafile, O_CREAT | O_WRONLY | O_SYNC, 0644)) < 0) {
printf("ERROR: writing to %s\n", datafile);
exit(1);
}
write_log(fd);
return (0);
}
|
the_stack_data/68888433.c | /*
gcc -std=c17 -lc -lm -pthread -o ../_build/c/numeric_complex_catan.exe ./c/numeric_complex_catan.c && (cd ../_build/c/;./numeric_complex_catan.exe)
https://en.cppreference.com/w/c/numeric/complex/catan
*/
#include <stdio.h>
#include <float.h>
#include <complex.h>
int main(void)
{
double complex z = catan(2*I);
printf("catan(+0+2i) = %f%+fi\n", creal(z), cimag(z));
double complex z2 = catan(-conj(2*I)); // or CMPLX(-0.0, 2)
printf("catan(-0+2i) (the other side of the cut) = %f%+fi\n", creal(z2), cimag(z2));
double complex z3 = 2*catan(2*I*DBL_MAX); // or CMPLX(0, INFINITY)
printf("2*catan(+0+i*Inf) = %f%+fi\n", creal(z3), cimag(z3));
}
|
the_stack_data/179831534.c | /* DataToC output of file <armature_sphere_solid_frag_glsl> */
extern int datatoc_armature_sphere_solid_frag_glsl_size;
extern char datatoc_armature_sphere_solid_frag_glsl[];
int datatoc_armature_sphere_solid_frag_glsl_size = 2620;
char datatoc_armature_sphere_solid_frag_glsl[] = {
13, 10, 35,101,120,116,101,110,115,105,111,110, 32, 71, 76, 95, 65, 82, 66, 95, 99,111,110,115,101,114,118, 97,116,105,118,101, 95,100,101,112,116,104, 32, 58, 32,101,110, 97, 98,108,101, 13, 10, 13, 10,117,110,105,102,111,114,109, 32,109, 97,116, 52, 32, 86,105,101,119, 77, 97,116,114,105,120, 73,110,118,101,114,115,101, 59, 13, 10,117,110,105,102,111,114,109, 32,109, 97,116, 52, 32, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 59, 13, 10,117,110,105,102,111,114,109, 32,102,108,111, 97,116, 32, 97,108,112,104, 97, 32, 61, 32, 48, 46, 52, 59, 13, 10, 13, 10,102,108, 97,116, 32,105,110, 32,118,101, 99, 51, 32,102,105,110, 97,108, 83,116, 97,116,101, 67,111,108,111,114, 59, 13, 10,102,108, 97,116, 32,105,110, 32,118,101, 99, 51, 32,102,105,110, 97,108, 66,111,110,101, 67,111,108,111,114, 59, 13, 10,102,108, 97,116, 32,105,110, 32,109, 97,116, 52, 32,115,112,104,101,114,101, 77, 97,116,114,105,120, 59, 13, 10,105,110, 32,118,101, 99, 51, 32,118,105,101,119, 80,111,115,105,116,105,111,110, 59, 13, 10, 13, 10, 35,105,102,100,101,102, 32, 71, 76, 95, 65, 82, 66, 95, 99,111,110,115,101,114,118, 97,116,105,118,101, 95,100,101,112,116,104, 13, 10, 47, 42, 32, 83, 97,118,101,115, 32, 97, 32,108,111,116, 32,111,102, 32,111,118,101,114,100,114, 97,119, 33, 32, 42, 47, 13, 10,108, 97,121,111,117,116, 40,100,101,112,116,104, 95,103,114,101, 97,116,101,114, 41, 32,111,117,116, 32,102,108,111, 97,116, 32,103,108, 95, 70,114, 97,103, 68,101,112,116,104, 59, 13, 10, 35,101,110,100,105,102, 13, 10, 13, 10,111,117,116, 32,118,101, 99, 52, 32,102,114, 97,103, 67,111,108,111,114, 59, 13, 10, 13, 10, 35,100,101,102,105,110,101, 32, 99, 97,109,101,114, 97, 80,111,115, 32, 86,105,101,119, 77, 97,116,114,105,120, 73,110,118,101,114,115,101, 91, 51, 93, 46,120,121,122, 13, 10, 13, 10,102,108,111, 97,116, 32,103,101,116, 95,100,101,112,116,104, 95,102,114,111,109, 95,118,105,101,119, 95,122, 40,102,108,111, 97,116, 32,122, 41, 13, 10,123, 13, 10, 9,105,102, 32, 40, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 91, 51, 93, 91, 51, 93, 32, 61, 61, 32, 48, 46, 48, 41, 32,123, 13, 10, 9, 9,122, 32, 61, 32, 40, 45, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 91, 51, 93, 91, 50, 93, 32, 47, 32,122, 41, 32, 45, 32, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 91, 50, 93, 91, 50, 93, 59, 13, 10, 9,125, 13, 10, 9,101,108,115,101, 32,123, 13, 10, 9, 9,122, 32, 61, 32,122, 32, 42, 32, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 91, 50, 93, 91, 50, 93, 32, 47, 32, 40, 49, 46, 48, 32, 45, 32, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 91, 51, 93, 91, 50, 93, 41, 59, 13, 10, 9,125, 13, 10, 9,114,101,116,117,114,110, 32,122, 32, 42, 32, 48, 46, 53, 32, 43, 32, 48, 46, 53, 59, 13, 10,125, 13, 10, 13, 10,118,111,105,100, 32,109, 97,105,110, 40, 41, 13, 10,123, 13, 10, 9, 99,111,110,115,116, 32,102,108,111, 97,116, 32,115,112,104,101,114,101, 95,114, 97,100,105,117,115, 32, 61, 32, 48, 46, 48, 53, 59, 13, 10, 13, 10, 9, 98,111,111,108, 32,105,115, 95,112,101,114,112, 32, 61, 32, 40, 80,114,111,106,101, 99,116,105,111,110, 77, 97,116,114,105,120, 91, 51, 93, 91, 51, 93, 32, 61, 61, 32, 48, 46, 48, 41, 59, 13, 10, 9,118,101, 99, 51, 32,114, 97,121, 95,111,114,105, 95,118,105,101,119, 32, 61, 32, 40,105,115, 95,112,101,114,112, 41, 32, 63, 32,118,101, 99, 51, 40, 48, 46, 48, 41, 32, 58, 32,118,105,101,119, 80,111,115,105,116,105,111,110, 46,120,121,122, 59, 13, 10, 9,118,101, 99, 51, 32,114, 97,121, 95,100,105,114, 95,118,105,101,119, 32, 61, 32, 40,105,115, 95,112,101,114,112, 41, 32, 63, 32,118,105,101,119, 80,111,115,105,116,105,111,110, 32, 58, 32,118,101, 99, 51, 40, 48, 46, 48, 44, 32, 48, 46, 48, 44, 32, 45, 49, 46, 48, 41, 59, 13, 10, 13, 10, 9, 47, 42, 32, 83,105,110,103,108,101, 32,109, 97,116,114,105,120, 32,109,117,108, 32,119,105,116,104,111,117,116, 32, 98,114, 97,110, 99,104, 46, 32, 42, 47, 13, 10, 9,118,101, 99, 52, 32,109,117,108, 95,118,101, 99, 32, 61, 32, 40,105,115, 95,112,101,114,112, 41, 32, 63, 32,118,101, 99, 52, 40,114, 97,121, 95,100,105,114, 95,118,105,101,119, 44, 32, 48, 46, 48, 41, 32, 58, 32,118,101, 99, 52, 40,114, 97,121, 95,111,114,105, 95,118,105,101,119, 44, 32, 49, 46, 48, 41, 59, 13, 10, 9,118,101, 99, 51, 32,109,117,108, 95,114,101,115, 32, 61, 32, 40,115,112,104,101,114,101, 77, 97,116,114,105,120, 32, 42, 32,109,117,108, 95,118,101, 99, 41, 46,120,121,122, 59, 13, 10, 13, 10, 9, 47, 42, 32, 82,101,109,105,110,100,101,114, 32, 58, 13, 10, 9, 32, 42, 32,115,112,104,101,114,101, 77, 97,116,114,105,120, 91, 51, 93, 32,105,115, 32,116,104,101, 32,118,105,101,119, 32,115,112, 97, 99,101, 32,111,114,105,103,105,110, 32,105,110, 32,115,112,104,101,114,101, 32,115,112, 97, 99,101, 32, 40,115,112,104, 95,111,114,105, 32, 45, 62, 32,118,105,101,119, 95,111,114,105, 41, 46, 13, 10, 9, 32, 42, 32,115,112,104,101,114,101, 77, 97,116,114,105,120, 91, 50, 93, 32,105,115, 32,116,104,101, 32,118,105,101,119, 32,115,112, 97, 99,101, 32, 90, 32, 97,120,105,115, 32,105,110, 32,115,112,104,101,114,101, 32,115,112, 97, 99,101, 46, 32, 42, 47, 13, 10, 13, 10, 9, 47, 42, 32, 99,111,110,118,101,114,116, 32,116,111, 32,115,112,104,101,114,101, 32,108,111, 99, 97,108, 32,115,112, 97, 99,101, 32, 42, 47, 13, 10, 9,118,101, 99, 51, 32,114, 97,121, 95,111,114,105, 32, 61, 32, 40,105,115, 95,112,101,114,112, 41, 32, 63, 32,115,112,104,101,114,101, 77, 97,116,114,105,120, 91, 51, 93, 46,120,121,122, 32, 58, 32,109,117,108, 95,114,101,115, 59, 13, 10, 9,118,101, 99, 51, 32,114, 97,121, 95,100,105,114, 32, 61, 32, 40,105,115, 95,112,101,114,112, 41, 32, 63, 32,109,117,108, 95,114,101,115, 32, 58, 32, 45,115,112,104,101,114,101, 77, 97,116,114,105,120, 91, 50, 93, 46,120,121,122, 59, 13, 10, 9,102,108,111, 97,116, 32,114, 97,121, 95,108,101,110, 32, 61, 32,108,101,110,103,116,104, 40,114, 97,121, 95,100,105,114, 41, 59, 13, 10, 9,114, 97,121, 95,100,105,114, 32, 47, 61, 32,114, 97,121, 95,108,101,110, 59, 13, 10, 13, 10, 9, 47, 42, 32, 76,105,110,101, 32,116,111, 32,115,112,104,101,114,101, 32,105,110,116,101,114,115,101, 99,116, 32, 42, 47, 13, 10, 9, 99,111,110,115,116, 32,102,108,111, 97,116, 32,115,112,104,101,114,101, 95,114, 97,100,105,117,115, 95,115,113,114, 32, 61, 32,115,112,104,101,114,101, 95,114, 97,100,105,117,115, 32, 42, 32,115,112,104,101,114,101, 95,114, 97,100,105,117,115, 59, 13, 10, 9,102,108,111, 97,116, 32, 98, 32, 61, 32,100,111,116, 40,114, 97,121, 95,111,114,105, 44, 32,114, 97,121, 95,100,105,114, 41, 59, 13, 10, 9,102,108,111, 97,116, 32, 99, 32, 61, 32,100,111,116, 40,114, 97,121, 95,111,114,105, 44, 32,114, 97,121, 95,111,114,105, 41, 32, 45, 32,115,112,104,101,114,101, 95,114, 97,100,105,117,115, 95,115,113,114, 59, 13, 10, 9,102,108,111, 97,116, 32,104, 32, 61, 32, 98, 32, 42, 32, 98, 32, 45, 32, 99, 59, 13, 10, 9,102,108,111, 97,116, 32,116, 32, 61, 32, 45,115,113,114,116, 40,109, 97,120, 40, 48, 46, 48, 44, 32,104, 41, 41, 32, 45, 32, 98, 59, 13, 10, 13, 10, 9, 47, 42, 32, 67,111,109,112,117,116,101, 32,100,111,116, 32,112,114,111,100,117, 99,116, 32,102,111,114, 32,108,105,103,104,116,105,110,103, 32, 42, 47, 13, 10, 9,118,101, 99, 51, 32,112, 32, 61, 32,114, 97,121, 95,100,105,114, 32, 42, 32,116, 32, 43, 32,114, 97,121, 95,111,114,105, 59, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 47, 42, 32, 80,111,105,110,116, 32,111,110, 32,115,112,104,101,114,101, 32, 42, 47, 13, 10, 9,118,101, 99, 51, 32,110, 32, 61, 32,110,111,114,109, 97,108,105,122,101, 40,112, 41, 59, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 47, 42, 32, 78,111,114,109, 97,108, 32,105,115, 32,106,117,115,116, 32,116,104,101, 32,112,111,105,110,116, 32,105,110, 32,115,112,104,101,114,101, 32,115,112, 97, 99,101, 44, 32,110,111,114,109, 97,108,105,122,101,100, 46, 32, 42, 47, 13, 10, 9,118,101, 99, 51, 32,108, 32, 61, 32,110,111,114,109, 97,108,105,122,101, 40,115,112,104,101,114,101, 77, 97,116,114,105,120, 91, 50, 93, 46,120,121,122, 41, 59, 32, 47, 42, 32, 74,117,115,116, 32,116,104,101, 32,118,105,101,119, 32, 90, 32, 97,120,105,115, 32,105,110, 32,116,104,101, 32,115,112,104,101,114,101, 32,115,112, 97, 99,101, 46, 32, 42, 47, 13, 10, 13, 10, 13, 10, 9, 47, 42, 32, 83,109,111,111,116,104, 32,108,105,103,104,116,105,110,103, 32,102, 97, 99,116,111,114, 46, 32, 42, 47, 13, 10, 9, 99,111,110,115,116, 32,102,108,111, 97,116, 32,115, 32, 61, 32, 48, 46, 50, 59, 32, 47, 42, 32, 91, 48, 46, 48, 45, 48, 46, 53, 93, 32,114, 97,110,103,101, 32, 42, 47, 13, 10, 9,102,108,111, 97,116, 32,102, 97, 99, 32, 61, 32, 99,108, 97,109,112, 40, 40,100,111,116, 40,110, 44, 32,108, 41, 32, 42, 32, 40, 49, 46, 48, 32, 45, 32,115, 41, 41, 32, 43, 32,115, 44, 32, 48, 46, 48, 44, 32, 49, 46, 48, 41, 59, 13, 10, 9,102,114, 97,103, 67,111,108,111,114, 46,114,103, 98, 32, 61, 32,109,105,120, 40,102,105,110, 97,108, 83,116, 97,116,101, 67,111,108,111,114, 44, 32,102,105,110, 97,108, 66,111,110,101, 67,111,108,111,114, 44, 32,102, 97, 99, 41, 59, 13, 10, 13, 10, 9, 47, 42, 32, 50,120, 50, 32,100,105,116,104,101,114, 32,112, 97,116,116,101,114,110, 32,116,111, 32,115,109,111,111,116,104, 32,116,104,101, 32,108,105,103,104,116,105,110,103, 46, 32, 42, 47, 13, 10, 9,102,108,111, 97,116, 32,100,105,116,104,101,114, 32, 61, 32, 40, 48, 46, 53, 32, 43, 32,100,111,116, 40,118,101, 99, 50, 40,105,118,101, 99, 50, 40,103,108, 95, 70,114, 97,103, 67,111,111,114,100, 46,120,121, 41, 32, 38, 32,105,118,101, 99, 50, 40, 49, 41, 41, 44, 32,118,101, 99, 50, 40, 49, 46, 48, 44, 32, 50, 46, 48, 41, 41, 41, 32, 42, 32, 48, 46, 50, 53, 59, 13, 10, 9,100,105,116,104,101,114, 32, 42, 61, 32, 40, 49, 46, 48, 32, 47, 32, 50, 53, 53, 46, 48, 41, 59, 32, 47, 42, 32, 65,115,115,117,109,101, 32, 56, 98,105,116, 32,112,101,114, 32, 99,111,108,111,114, 32, 98,117,102,102,101,114, 46, 32, 42, 47, 13, 10, 13, 10, 9,102,114, 97,103, 67,111,108,111,114, 32, 61, 32,118,101, 99, 52, 40,102,114, 97,103, 67,111,108,111,114, 46,114,103, 98, 32, 43, 32,100,105,116,104,101,114, 44, 32, 97,108,112,104, 97, 41, 59, 13, 10, 13, 10, 9,116, 32, 47, 61, 32,114, 97,121, 95,108,101,110, 59, 13, 10, 9,103,108, 95, 70,114, 97,103, 68,101,112,116,104, 32, 61, 32,103,101,116, 95,100,101,112,116,104, 95,102,114,111,109, 95,118,105,101,119, 95,122, 40,114, 97,121, 95,100,105,114, 95,118,105,101,119, 46,122, 32, 42, 32,116, 32, 43, 32,114, 97,121, 95,111,114,105, 95,118,105,101,119, 46,122, 41, 59, 13, 10,125, 13, 10,0
};
|
the_stack_data/75471.c | #include<stdio.h>
int f[50], i, k, j, inde[50], n, c, count=0, p;
int main()
{
for(i = 0; i < 50; i++)
f[i] = 0;
x:
printf(" Enter index block: ");
scanf("%d", &p);
if(f[p] == 0)
{
f[p] = 1;
printf(" Enter number of files on index: ");
scanf("%d", &n);
}
else {
printf(" Block already allocated\n");
goto x;
}
printf(" Enter values: \n");
for(i = 0; i < n; i++)
scanf("%d", &inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]] == 1)
{
printf(" ERR: Block already allocated");
goto x;
}
for(j = 0; j < n; j++)
f[inde[j]] = 1;
printf("\n Allocated: ");
printf("\n File indexed: ");
for(k = 0; k < n; k++)
printf("\n%d -> %d:%d", p, inde[k], f[inde[k]]);
printf(" Press 1 to enter more files \n 0 to exit\t");
scanf("%d", &c);
if(c == 1)
goto x;
else
return(0);
} |
the_stack_data/52337.c | #include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 12
#define INPUT "input.txt"
int main(){
int totalNumbers, ones[MAX_LEN];
FILE* input = fopen(INPUT, "r");
char string[MAX_LEN + 1];
int i;
int gamma = 0, epsilon = 0;
for ( i = 0; i < MAX_LEN; i++)
ones[i] = 0;
// counts all '1' in each position and keeps track of iterations done (so to know total number count)
while( fscanf(input, "%s", string) != EOF){
//printf("%s\n", string);
for(i = 0; i< MAX_LEN; i++)
ones[i] += string[i] - '0';
//ones[i] += string[i] == '0' ? 0 : 1;
totalNumbers ++;
}
fclose(input);
totalNumbers /= 2; // needed to see if totalNumbers counted more or less '1' than half total numbers
for(i = 0; i< MAX_LEN; i++){
// easy way to convert from binary to decimal
gamma *= 2;
epsilon *= 2;
gamma += ones[i] > totalNumbers ? 1 : 0;
epsilon += ones[i] < totalNumbers ? 1 : 0;
}
printf("Result part 1 = %d\n", gamma*epsilon);
return 0;
} |
the_stack_data/64200916.c | int main()
{
int a[10], b[10];
int x, y, z;
__CPROVER_assume(2 <= y && y <= 4);
__CPROVER_assume(6 <= z && z <= 8);
b[y] = x;
b[z] = x;
for(unsigned i = 0; i < 10; i++)
{
a[i] = b[i];
}
__CPROVER_assert(a[y] == a[z], "a[y]==a[z]");
}
|
the_stack_data/132953875.c | #include <stdio.h>
#include <math.h>
int main() {
double radius, area;
scanf("%lf", &radius);
area = 3.14159 * pow(radius, 2);
printf("A=%.4f\n", area);
return 0;
} |
the_stack_data/25839.c | #include<stdio.h>
#include<string.h>
void RabinKarp(char pat[], char txt[], int q,int d)
{
int M = strlen(pat);
int N = strlen(txt);
int i, j;
int p = 0; // hash value for pattern
int t = 0; // hash value for txt
int h = 1;
// The value of h would be "pow(d, M-1)%q"
for (i = 0; i < M-1; i++)
h = (h*d)%q;
// Calculate the hash value
for (i = 0; i < M; i++)
{
p = (d*p + pat[i])%q;
t = (d*t + txt[i])%q;
}
// Slide the pattern over text one by one
for (i = 0; i <= N - M; i++)
{
// Check the hash values of current window of text
// and pattern. If the hash values match then only
// check for characters on by one
if ( p == t )
{
/* Check for characters one by one */
for (j = 0; j < M; j++)
{
if (txt[i+j] != pat[j])
break;
}
// if p == t and pat[0...M-1] = txt[i, i+1, ...i+M-1]
if (j == M)
printf("Pattern found at index %d \n", i);
}
// Calculate hash value for next window of text: Remove
// leading digit, add trailing digit
if ( i < N-M )
{
t = (d*(t - txt[i]*h) + txt[i+M])%q;
// We might get negative value of t, converting it
// to positive
if (t < 0)
t = (t + q);
}
}
}
/* Driver program to test above function */
int main()
{
char txt[] = "Hello World";
char pat[] = "World";
int q = 101; // A prime number
RabinKarp(pat, txt, q,256);
return 0;
} |
the_stack_data/178265994.c | // string1.c -- read a string in without checking input length
// copyright 2015 robert holder, MIT license
// https://github.com/rdholder/cursim
// this is a good example of why getnstr() is necessary to avoid
// smashing the stack. at the command line, type:
// ulimit -c unlimited
// ...to enable core file writing. then run the string1 program, and type
// in names longer than the array sizes (24 or 32) to clobber memory. then:
// gdb string1 core
// ... then type
// where
// ... to see where the coredump occurred.
#include <stdlib.h>
#include <ncurses.h>
#include <time.h>
#include <math.h>
int main(void)
{
char first[24];
char last[32];
initscr();
addstr("What is your first name? ");
refresh();
getstr(first);
addstr("What is your last name? ");
refresh();
getstr(last);
printw("Pleased to meet you, %s %s! Hope you guessed my name", first, last);
refresh();
getch();
endwin();
return(0);
}
|
the_stack_data/144442.c | #include <pthread.h>
#include <assert.h>
int g = 17; // matches expected precise read
pthread_mutex_t A = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t B = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t C = PTHREAD_MUTEX_INITIALIZER;
void *t_fun(void *arg) {
pthread_mutex_lock(&B);
pthread_mutex_lock(&C);
g = 42;
pthread_mutex_unlock(&B);
g = 17;
pthread_mutex_unlock(&C);
return NULL;
}
int main(void) {
pthread_t id;
pthread_create(&id, NULL, t_fun, NULL);
pthread_mutex_lock(&A);
pthread_mutex_lock(&B);
pthread_mutex_lock(&C);
assert(g == 17);
pthread_mutex_unlock(&A);
pthread_mutex_unlock(&B);
pthread_mutex_unlock(&C);
return 0;
}
|
the_stack_data/26701454.c | /* $XFree86: xc/programs/Xserver/hw/dmx/examples/evi.c,v 1.1 2004/06/30 20:21:43 martin Exp $ */
/*
* Copyright 2003 Red Hat Inc., Durham, North Carolina.
*
* 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 on 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
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
* 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.
*/
/*
* Authors:
* Rickard E. (Rik) Faith <[email protected]>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/extensions/XEVI.h>
int main(int argc, char **argv)
{
Display *display = NULL;
int major_version, minor_version;
ExtendedVisualInfo *evi;
int count;
int i;
if (argc == 2) {
if (!(display = XOpenDisplay(argv[1]))) {
printf("Cannot open display %s\n", argv[1]);
return -1;
}
} else {
printf("Usage: %s display\n", argv[0]);
return -1;
}
if (!display && !(display = XOpenDisplay(NULL))) {
printf("Cannot open default display\n");
return -1;
}
if (!XeviQueryVersion(display, &major_version, &minor_version)) {
printf("EVI extension not present\n");
return -1;
}
printf("EVI Extension version: %d.%d\n", major_version, minor_version);
XeviGetVisualInfo(display, NULL, 0, &evi, &count);
for (i = 0; i < count; i++) {
printf("%02d vid=0x%02lx screen=%d level=%d type=%u value=%u"
" min=%u max=%u conflicts=%u\n",
i,
(long unsigned)evi[i].core_visual_id,
evi[i].screen,
evi[i].level,
evi[i].transparency_type,
evi[i].transparency_value,
evi[i].min_hw_colormaps,
evi[i].max_hw_colormaps,
evi[i].num_colormap_conflicts);
}
XCloseDisplay(display);
return 0;
}
|
the_stack_data/117328127.c | // This code is adopted from http://algs4.cs.princeton.edu/33balanced/SplayBST.java.html
#include<stdio.h>
#include<stdlib.h>
// An AVL tree node
struct node
{
int key;
struct node *left, *right;
};
/* Helper function that allocates a new node with the given key and
NULL left and right pointers. */
struct node* newNode(int key)
{
struct node* node = (struct node*)malloc(sizeof(struct node));
node->key = key;
node->left = node->right = NULL;
return (node);
}
// A utility function to right rotate subtree rooted with y
// See the diagram given above.
struct node *rightRotate(struct node *x)
{
struct node *y = x->left;
x->left = y->right;
y->right = x;
return y;
}
// A utility function to left rotate subtree rooted with x
// See the diagram given above.
struct node *leftRotate(struct node *x)
{
struct node *y = x->right;
x->right = y->left;
y->left = x;
return y;
}
// This function brings the key at root if key is present in tree.
// If key is not present, then it brings the last accessed item at
// root. This function modifies the tree and returns the new root
struct node *splay(struct node *root, int key)
{
// Base cases: root is NULL or key is present at root
if (root == NULL || root->key == key)
return root;
// Key lies in left subtree
if (root->key > key)
{
// Key is not in tree, we are done
if (root->left == NULL) return root;
// Zig-Zig (Left Left)
if (root->left->key > key)
{
// First recursively bring the key as root of left-left
root->left->left = splay(root->left->left, key);
// Do first rotation for root, second rotation is done after else
root = rightRotate(root);
}
else if (root->left->key < key) // Zig-Zag (Left Right)
{
// First recursively bring the key as root of left-right
root->left->right = splay(root->left->right, key);
// Do first rotation for root->left
if (root->left->right != NULL)
root->left = leftRotate(root->left);
}
// Do second rotation for root
return (root->left == NULL)? root: rightRotate(root);
}
else // Key lies in right subtree
{
// Key is not in tree, we are done
if (root->right == NULL) return root;
// Zig-Zag (Right Left)
if (root->right->key > key)
{
// Bring the key as root of right-left
root->right->left = splay(root->right->left, key);
// Do first rotation for root->right
if (root->right->left != NULL)
root->right = rightRotate(root->right);
}
else if (root->right->key < key)// Zag-Zag (Right Right)
{
// Bring the key as root of right-right and do first rotation
root->right->right = splay(root->right->right, key);
root = leftRotate(root);
}
// Do second rotation for root
return (root->right == NULL)? root: leftRotate(root);
}
}
// Function to insert a new key k in splay tree with given root
struct node *insert(struct node *root, int k)
{
// Simple Case: If tree is empty
if (root == NULL) return newNode(k);
// Bring the closest leaf node to root
root = splay(root, k);
// If key is already present, then return
if (root->key == k) return root;
// Otherwise allocate memory for new node
struct node *newnode = newNode(k);
// If root's key is greater, make root as right child
// of newnode and copy the left child of root to newnode
if (root->key > k)
{
newnode->right = root;
newnode->left = root->left;
root->left = NULL;
}
// If root's key is smaller, make root as left child
// of newnode and copy the right child of root to newnode
else
{
newnode->left = root;
newnode->right = root->right;
root->right = NULL;
}
return newnode; // newnode becomes new root
}
// A utility function to print preorder traversal of the tree.
// The function also prints height of every node
void preOrder(struct node *root)
{
if (root != NULL)
{
printf("%d ", root->key);
preOrder(root->left);
preOrder(root->right);
}
}
/* Drier program to test above function*/
int main()
{
struct node *root = newNode(100);
root->left = newNode(50);
root->right = newNode(200);
root->left->left = newNode(40);
root->left->left->left = newNode(30);
root->left->left->left->left = newNode(20);
root = insert(root, 25);
printf("Preorder traversal of the modified Splay tree is \n");
preOrder(root);
return 0;
}
|
the_stack_data/165768410.c | /* 1. Devido ao afastamento social em decorrência da pandemia, a sessão de Cinema "Maliarte conta +1História"
* optou por oferecer conforto e segurança aos seus assinantes.
Para isso disponibilizou o dowload de filmes.
O acervo conta com 10 obras, com as seguintes informações:
Numero do Filme: 110, 120, 130, 140, 150, 160, 170, 180, 190, 200
com os seguintes títulos:
* 110 - O cachorro Muito Louco
* 120 - Operação Storm
* 130 - Aranha da Janela
* 140 - Entre santos e desencantos
* 150 - As estrelas tambem morrem, todavia não fazem upload
* 160 - Raspadinha
* 170 - Matrix
* 180 - Sempre tem um
* 190 - Pedra Lascada
* 200- Fome Castiga
* Escreva um programa que mediante a inserção do título o usuário informa a origem do conhecimento do mesmo:
* 1) Indicação da plataforma;
* 2) Outra origem;
*
*
* Após isso, registre:
* a quantidade de downloads de cada título.
*
* O relatório final do programa deve:
* a)exibir o título mais baixado (desconsidere empates) e o título menos baixado (no vetor acumulador);
* b)exiba a quantidade de filmes que foram baixados com indicação da plataforma (no vetor plataforma);
* c) e de outra forma (no vetor outro);
*/
#include <stdio.h>
#define TAM 10
void preencheVetor(int vetor[], int valor);
int valida(int referencia);
void exibe(int vAcumulador[]);
void moldura();
int main(void){
int vFilme[TAM] = {110, 120, 130, 140, 150, 160, 170, 180, 190, 200};
int vPlataforma[TAM];
int vOutro[TAM];
int vAcumulador[TAM];
int login;
int indicacao;
int cod;
int pos;
////
int download,maior,menor;
int i;
preencheVetor(vPlataforma, 0);
preencheVetor(vOutro, 0);
preencheVetor(vAcumulador, 0);
moldura();
printf("Digite o login ou 0 para sair:\n");
moldura();
scanf("%i", &login);
while(login > 0){
cod = valida(1);
pos = (cod / 10) - 11; //define padrão math para acesso direto
indicacao = valida(2);
if(indicacao == 1){
vPlataforma[pos]++;
} else{
vOutro[pos]++;
}
vAcumulador[pos]++;
moldura();
printf("\nDigite o login ou 0 para sair:\n");
scanf("%i", &login);
moldura();
}
/*
for(int i = 0; i < TAM; i++){
printf("Filme %d\n", vFilme[i]);
}
for(int i = 0; i < TAM; i++){
printf("Plataforma %d\n", vPlataforma[i]);
}
for(int i = 0; i < TAM; i++){
printf("outro %d\n", vOutro[i]);
}
for(int i = 0; i < TAM; i++){
printf("Acumulador %d\n", vAcumulador[i]);
}
*/
//////////// qtd dowload de cada título, tenho variavel cod que armazena o cod do filme que o usuario deseja preciso relacionar com o vFilme?
for(i = 0 ; i < TAM; i++) {
download += vAcumulador[i];
}
exibe(vAcumulador);
///////////////////////Throne/////////////////////
maior = vAcumulador[0]; //inicializa variavel maior com 1ºvalor do vetor
//logo controler começa da proxima posição do vetor
for ( i=1; i<TAM; i++) {
if (vAcumulador[i] > maior) {
maior = vAcumulador[i]; //substitui
}
pos = vAcumulador[i]++;
}
//exibe//
printf("\n||Maior: %d||\n| HIT: %d", maior, pos);
///////////////Menor download/////////////////////
menor = vAcumulador[0]; //inicializa variavel menor com 1ºvalor do vetor
//logo controler começa da proxima posição do vetor
for ( i=1; i<TAM; i++) {
if (vAcumulador[i] < menor) {
menor = vAcumulador[i]; //substitui
}
pos = vAcumulador[i]++;
}
//exibe//
printf("\n||Menor: %d||\n| MISS: %d", menor, pos);
return 0;
}/////////////////////// FIM MAIN/////////////////////
/////////////////////////////////////////////////////////////
void preencheVetor(int vetor[], int valor){
for(int i = 0; i < TAM; i++){
vetor[i] = valor;
}
}
/////////////////////////////////////////////////////////////
int valida(int referencia){
int cod;
int indicacao;
int valor;
if(referencia == 1){// valida codigo do filme
moldura();
printf("Informe o código do filme:\n110 - O cachorro Muito Louco \n120 - Operação Storm\n130 - Aranha da Janela\n140 - Entre santos e desencantos \n150 - As estrelas tambem morrem, todavia não fazem upload\n160 - Raspadinha \n170 - Matrix \n180 - Sempre tem um \n190 - Pedra Lascada \n200 - Fome Castiga\n");
moldura();
scanf("%i", &cod);
while( (cod < 110 || cod > 200) || cod%10 != 0){
moldura();
printf("Digitação Inválida. Confirme o valor e tente novamente.");
printf("Informe o código do filme:\n110 - O cachorro Muito Louco \n120 - Operação Storm\n130 - Aranha da Janela\n140 - Entre santos e desencantos \n150 - As estrelas tambem morrem, todavia não fazem upload\n160 - Raspadinha \n170 - Matrix \n180 - Sempre tem um \n190 - Pedra Lascada \n200 - Fome Castiga\n");
moldura();
scanf("%i", &cod);
}
valor = cod;
}else{// valida indicacao
moldura();
printf("Informe a origem da indicação:\n");
printf("1 - plataforma\n");
printf("2 - outro\n");
moldura();
scanf("%i", &indicacao);
while(indicacao < 1 || indicacao > 2){
moldura();
printf("Digitação Inválida. Tente novamente.");
moldura();
printf("Informe a origem da indicação:\n");
printf("1 - plataforma\n");
printf("2 - outro\n");
moldura();
scanf("%i", &indicacao);
}
valor = indicacao;
}
return valor;
}
/////////////////////////////////////////////////////////////
void exibe(int vAcumulador[]){
printf("=======RELATÓRIO DOWNLOAD FILMES:========\n");
printf("110 - O cachorro Muito Louco | %d download.\n", vAcumulador[0]);
printf("120 - Operação Storm | %d download.\n", vAcumulador[1]);
printf("130 - Aranha da Janela | %d download.\n", vAcumulador[2]);
printf("140 - Entre santos e desencantos| %d download.\n", vAcumulador[3]);
printf("150 - As estrelas tambem morrem | %d download.\n", vAcumulador[4]);
printf("160 - Raspadinha | %d download.\n", vAcumulador[5]);
printf("170 - Matrix | %d download.\n", vAcumulador[6]);
printf("180 - Sempre tem um | %d download.\n", vAcumulador[7]);
printf("190 - Pedra Lascada | %d download.\n", vAcumulador[8]);
printf("200- Fome Castiga | %d download.\n", vAcumulador[9]);
printf("==========================================\n");
}
//////////////////////// moldura////
void moldura(){
printf("===============");
printf("===============");
printf("===============\n");
} |
the_stack_data/588339.c | #include <stdio.h>
int main()
{
int t, x;
scanf("%d", &t);
while (t--)
{
scanf("%d", &x);
printf("%d %d\n", 1, x - 1);
}
return 0;
} |
the_stack_data/248580215.c |
/**
* calculating the day of the year since 1 January of the given year
*
*
* returning the days if the date exists, returns -1 if the date does not exists
*
*/
int day_of_the_year(int day, int month, int year)
{
if(!exists_date(year,month,day))
{
return -1;
}
int days = 0; // a counter to count the days
for(int i = 1; i < month; i++)
{
days += get_days_for_month(year, i); // calculates the days
}
return days += day;
}
/**
* gets the user input and writes them into the vars, the "*year"
* stand for a pointer which is pointing at the year var address
*
* etc. for month and day
*/
void input_date(int *year, int *month, int *day)
{
do
{
printf("Enter the year:");
scanf("%i", year);
printf("Enter the day:");
scanf("%i", day);
printf("Enter the month:");
scanf("%i", month);
}
while(!exists_date(*year,*month,*day));
}
/**
*
* \param day, user input of days
* \param month, user input of month
* \param day_each_month, the amount of days each month
* \return 0 if the user input is incorrect, 1 if the input is correct
*
*/
int exists_date(int year, int month, int day)
{
if(month < 0)
{
return 0;
}
if(month > 12)
{
return 0;
}
if(day <= 0 || day > get_days_for_month(year, month))
{
return 0;
}
return 1;
}
/**
* \param year, user input of year
* \param month, user input of year
* \return amount of days or -1 if something is invalid
*/
int get_days_for_month(int year, int month)
{
int days_each_month[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; // the array of the months
int leapyear = is_leapyear(year);
if(leapyear == 1)
{
days_each_month[1] = 29; // sets the 2 Months on 29 days if its a leapyear
}
else if(leapyear == -1)
{
return -1;
}
if(month > 12 || month < 1)
{
return -1; // invalid month
}
if(year <= 0)
{
return -1; //invalid year
}
return days_each_month[month];
}
/**
*
* \param year, gets the user input of years
* \return 1 if its an leap year, 0 if not, -1 if the year is invalid
*
*/
int is_leapyear(int year)
{
if(year > 0)
{
if(((year%4==0) && ((year%400==0) || (year%100!=0))))
{
return 1;
}
else
{
return 0;
}
}
else
{
return -1;
}
}
|
the_stack_data/173577331.c | #include <stdio.h>
int main(void) {
int n;
printf("Enter a number between 0 and 32767: ");
scanf("%d", &n);
int n1 = n % 8;
n /= 8;
int n2 = n % 8;
n /= 8;
int n3 = n % 8;
n /= 8;
int n4 = n % 8;
n /= 8;
int n5 = n % 8;
printf("In octal, your number is: %d%d%d%d%d\n", n5, n4, n3, n2, n1);
return 0;
}
// Enter a number between 0 and 32767: 1953 |
the_stack_data/146911.c | #include <stdio.h>
#include <stdlib.h>
int SumLast40Digits(char *line_ptr[]) {
int col = 0;
int line_num = 0;
int num_lines = 100;
int carry = 0;
// col goes from the unit's place, ten's place, hundred's place and so on.
for (col = 0; col < 50; ++col) {
int column_sum = carry;
for (line_num = 0; line_num < num_lines; ++line_num) {
column_sum += (int)line_ptr[line_num][49 - col] - '0';
}
carry = column_sum/10;
}
return carry;
}
/* line_ptr - is an array pointers to each line. Each line contains one 50 digits number.
* carry - is the carry from adding the last 40 digits
* result_sum_first_10 - is an array of digits that are obtained from adding the numbers.
* Pre-allocate it to a size of 10.
* zeroth index of the array is actually the units place in the
* final sum.
*/
void SumFirst10Digits(char *line_ptr[], int carry, int *result_sum_first_10) {
int col = 0;
int line_num = 0;
int column_sum = 0;
int num_lines = 100;
// col goes from the unit's place, ten's place, hundred's place and so on.
for (col = 40; col < 49; ++col) {
column_sum = carry;
for (line_num = 0; line_num < num_lines; ++line_num) {
column_sum += (int)line_ptr[line_num][49 - col] - '0';
}
carry = column_sum/10;
result_sum_first_10[col - 40] = column_sum%10;
// printf("carry from this column is %d\n", carry);
}
column_sum = carry;
printf("column_sum before last column is %d\n", column_sum);
printf("Value of col is %d\n", col);
// for the last column, no need of generating a carry
for (line_num = 0; line_num < num_lines; ++line_num) {
column_sum += ((int)line_ptr[line_num][49 - col] - '0');
/* printf("line in the loop is %d\n", (int)line_ptr[line_num][49 - col] - '0'); */
}
result_sum_first_10[col - 40] = column_sum;
}
int main(int argc, char *argv[]) {
FILE *fp;
int i = 0;
int j = 0;
char *line;
int num_digits = 50;
int num_lines = 100;
char *line_ptr[num_lines];
/* adding 1 for the \0 */
if (argc == 1) { /* no args */
fprintf(stderr, "Please provide a data file as argument\n");
return 1;
} else if (argc == 2) {
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "Unable to open %s\n", argv[1]);
return 2;
}
printf("Reading in lines\n");
/* the problem statement says the number of lines is 100. */
for (i = 0; i < num_lines; ++i) {
line = (char*)malloc(num_digits+2);
// num_digits + 1 characters are read. +1 for \n character.
fgets(line, num_digits+2, fp);
for (j = 0; j < 50; ++j) {
printf("%c ", line[j]);
}
printf("\n");
line_ptr[i] = line;
}
int carry = SumLast40Digits(line_ptr);
fprintf(stdout, "Carry from the Last 40 Digits is %d\n", carry);
// zeroth index is unit's place, index 1 is the ten's place and so on.
int result_sum_first_10[10];
SumFirst10Digits(line_ptr, carry, result_sum_first_10);
// Printing the sum
printf("First few digits of the sum are here:\n");
for (i = 9; i >= 0; --i) {
fprintf(stdout, "%d", result_sum_first_10[i]);
}
fprintf(stdout, "\n");
}
return 0;
}
|
the_stack_data/31386790.c | /*
* Copyright (c) 2008, BSC (Barcelon Supercomputing Center)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY BSC ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <math.h>
#include <time.h>
#define NB 32
#define B 128
#define FALSE (0)
#define TRUE (1)
typedef double fp_type;
typedef fp_type *vin;
typedef fp_type *vout;
typedef fp_type *bin;
typedef fp_type *binout;
fp_type *A[NB][NB];
fp_type *A_new[NB][NB];
fp_type *tmp[NB][NB];
fp_type blockDelta[NB][NB];
void alloc_and_genmat()
{
int init_val, i, j, ii, jj;
fp_type *p, *p_new;
init_val = 1325;
for (ii = 0; ii < NB; ii++)
{
for (jj = 0; jj < NB; jj++)
{
A[ii][jj] = (fp_type *)malloc(B * B * sizeof(fp_type));
A_new[ii][jj] = (fp_type *)malloc(B * B * sizeof(fp_type));
tmp[ii][jj] = (fp_type *)malloc(B * B * sizeof(fp_type));
blockDelta[ii][jj] = 0.0;
if (A[ii][jj] == NULL || A_new[ii][jj] == NULL || tmp[ii][jj] == NULL)
{
printf("Out of memory\n");
exit(1);
}
p = A[ii][jj];
p_new = A_new[ii][jj];
for (i = 0; i < B; i++)
{
for (j = 0; j < B; j++)
{
init_val = (3125 * init_val) % 65536;
(*p) = (fp_type)((init_val - 32768.0) / 16384.0);
(*p_new) = (*p);
p++;
p_new++;
}
}
}
}
}
long usecs(void)
{
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec * 1000000 + t.tv_usec;
}
void clear(vout v)
{
int i, j, k;
for (i = 0; i < B; i++)
v[i] = (fp_type)0.0;
}
void getlastrow(bin A, vout v)
{
int j;
for (j = 0; j < B; j++)
v[j] = A[(B - 1) * B + j];
}
void getlastcol(bin A, vout v)
{
int i;
for (i = 0; i < B; i++)
v[i] = A[i * B + B - 1];
}
void getfirstrow(bin A, vout v)
{
int j;
for (j = 0; j < B; j++)
v[j] = A[0 * B + j];
}
void getfirstcol(bin A, vout v)
{
int i;
for (i = 0; i < B; i++)
v[i] = A[i * B + 0];
}
void jacobi(vin lefthalo, vin tophalo, vin righthalo, vin bottomhalo, bin A, binout A_new, fp_type* blockDelta)
{
int i, j;
fp_type tmp;
fp_type left, top, right, bottom;
fp_type fullResult, deltaErr = 0.0;
for (i = 0; (i < B); i++)
{
for (j = 0; j < B; j++)
{
tmp = A[i * B + j];
left = (j == 0 ? lefthalo[j] : A[i * B + j - 1]);
top = (i == 0 ? tophalo[i] : A[(i - 1) * B + j]);
right = (j == B - 1 ? righthalo[i] : A[i * B + j + 1]);
bottom = (i == B - 1 ? bottomhalo[i] : A[(i + 1) * B + j]);
// A_new[i * B + j] = 0.2 * (A[i * B + j] + left + top + right + bottom);
fullResult = 0.2 * (A[i * B + j] + left + top + right + bottom);
A_new[i * B + j] = fullResult;
// record difference between full result and stored value
// (*blockDelta) += fabs(fullResult - A_new[i * B + j])
fp_type deltaTmp = (*blockDelta);
fp_type y = fabs(fullResult - A_new[i * B + j]) + deltaErr;
(*blockDelta) = deltaTmp + y;
deltaErr = deltaTmp - (*blockDelta);
deltaErr += y;
}
}
}
double maxdelta()
{
double dmax = -__DBL_MAX__;
int ii, jj, i, j;
#pragma omp parallel for reduction(max: dmax)
for (ii = 0; ii < NB; ii++)
{
for (jj = 0; jj < NB; jj++)
{
for (i = 0; (i < B); i++)
{
for (j = 0; j < B; j++)
{
double diff = fabs(A_new[ii][jj][i * B + j] - A[ii][jj][i * B + j]);
if(diff > dmax) dmax = diff;
}
}
}
}
return dmax;
}
void compute(int niters)
{
int iters;
int ii, jj;
fp_type lefthalo[B], tophalo[B], righthalo[B], bottomhalo[B];
double delta = 2.0;
double epsilon = 1e-4;
iters = 0;
// for (iters = 0; iters < niters; iters++)
while(delta > epsilon)
{
++iters;
#pragma omp parallel \
private(ii, jj, lefthalo, tophalo, righthalo, bottomhalo) \
shared(A, A_new, blockDelta)
{
#pragma omp for schedule(static)
for (ii = 0; ii < NB; ii++)
{
for (jj = 0; jj < NB; jj++)
{
if (ii > 0)
getlastrow(A[ii - 1][jj], tophalo);
else
clear(tophalo);
if (jj > 0)
getlastcol(A[ii][jj - 1], lefthalo);
else
clear(lefthalo);
if (ii < NB - 1)
getfirstrow(A[ii + 1][jj], bottomhalo);
else
clear(bottomhalo);
if (jj < NB - 1)
getfirstcol(A[ii][jj + 1], righthalo);
else
clear(lefthalo);
jacobi(lefthalo, tophalo, righthalo, bottomhalo, A[ii][jj], A_new[ii][jj], &blockDelta[ii][jj]);
} // jj
} // ii
} // end parallel
delta = maxdelta();
printf("iteration %d: delta = %e\n", iters, delta);
// yes, this is an inefficient copy
// however, the library version requires you to do a copy in this way
// on all of the component parts to avoid segmentation fault
for(int i = 0; i < NB; ++i)
{
for(int j = 0; j < NB; ++j)
{
for(int k = 0; k < B; ++k)
{
for(int l = 0; l < B; ++l)
{
A[i][j][k * B + l] = A_new[i][j][k * B + l];
}
}
}
}
} // iter
}
int main(int argc, char *argv[])
{
int niters;
// pp_time_t tm;
// memset( &tm, 0, sizeof(tm) );
struct timespec start, end;
if (argc > 1)
{
niters = atoi(argv[1]);
}
else
niters = 1;
alloc_and_genmat();
clock_gettime(CLOCK_MONOTONIC, &start);
compute(niters);
clock_gettime(CLOCK_MONOTONIC, &end);
double time_taken = (end.tv_sec - start.tv_sec) * 1e9;
time_taken = (time_taken + (end.tv_nsec - start.tv_nsec)) * 1e-9;
printf("Running time = %g %s\n", time_taken, "s");
FILE *outFile;
outFile = fopen("./jacobi_omp_values.txt", "w");
if (outFile == NULL)
{
fprintf(stderr, "Error writing to file\n");
}
else
{
int ii, jj, i, j;
for (ii = 0; ii < NB; ++ii)
for (jj = 0; jj < NB; ++jj)
for (i = 0; i < B; ++i)
for (j = 0; j < B; ++j)
fprintf(outFile, "%.15f\n", A[ii][jj][i * B + j]);
fclose(outFile);
}
return 0;
} |
the_stack_data/933072.c | /*
* Copyright (c) 1987, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* %sccs.include.redist.c%
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1987, 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 06/06/93";
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/signal.h>
#include <stdio.h>
main(argc, argv)
int argc;
char **argv;
{
extern int optind;
register int pid;
int ch, status, lflag;
struct timeval before, after;
struct rusage ru;
lflag = 0;
while ((ch = getopt(argc, argv, "l")) != EOF)
switch((char)ch) {
case 'l':
lflag = 1;
break;
case '?':
default:
fprintf(stderr, "usage: time [-l] command.\n");
exit(1);
}
if (!(argc -= optind))
exit(0);
argv += optind;
gettimeofday(&before, (struct timezone *)NULL);
switch(pid = vfork()) {
case -1: /* error */
perror("time");
exit(1);
/* NOTREACHED */
case 0: /* child */
execvp(*argv, argv);
perror(*argv);
_exit(1);
/* NOTREACHED */
}
/* parent */
(void)signal(SIGINT, SIG_IGN);
(void)signal(SIGQUIT, SIG_IGN);
while (wait3(&status, 0, &ru) != pid); /* XXX use waitpid */
gettimeofday(&after, (struct timezone *)NULL);
if (status&0377)
fprintf(stderr, "Command terminated abnormally.\n");
after.tv_sec -= before.tv_sec;
after.tv_usec -= before.tv_usec;
if (after.tv_usec < 0)
after.tv_sec--, after.tv_usec += 1000000;
fprintf(stderr, "%9ld.%02ld real ", after.tv_sec, after.tv_usec/10000);
fprintf(stderr, "%9ld.%02ld user ",
ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000);
fprintf(stderr, "%9ld.%02ld sys\n",
ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000);
if (lflag) {
int hz = 100; /* XXX */
long ticks;
ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000;
fprintf(stderr, "%10ld %s\n",
ru.ru_maxrss, "maximum resident set size");
fprintf(stderr, "%10ld %s\n",
ru.ru_ixrss / ticks, "average shared memory size");
fprintf(stderr, "%10ld %s\n",
ru.ru_idrss / ticks, "average unshared data size");
fprintf(stderr, "%10ld %s\n",
ru.ru_isrss / ticks, "average unshared stack size");
fprintf(stderr, "%10ld %s\n",
ru.ru_minflt, "page reclaims");
fprintf(stderr, "%10ld %s\n",
ru.ru_majflt, "page faults");
fprintf(stderr, "%10ld %s\n",
ru.ru_nswap, "swaps");
fprintf(stderr, "%10ld %s\n",
ru.ru_inblock, "block input operations");
fprintf(stderr, "%10ld %s\n",
ru.ru_oublock, "block output operations");
fprintf(stderr, "%10ld %s\n",
ru.ru_msgsnd, "messages sent");
fprintf(stderr, "%10ld %s\n",
ru.ru_msgrcv, "messages received");
fprintf(stderr, "%10ld %s\n",
ru.ru_nsignals, "signals received");
fprintf(stderr, "%10ld %s\n",
ru.ru_nvcsw, "voluntary context switches");
fprintf(stderr, "%10ld %s\n",
ru.ru_nivcsw, "involuntary context switches");
}
exit (status>>8);
}
|
the_stack_data/180899.c | #include <stdio.h>
int main()
{
int x, y, z;
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &z);
int a;
int b;
a = x-y;
if (z > a)
{
b = z-a;
printf("%d", b);
}
else
{
printf("The volume of bottle b should be more than what is left in bottle a. ");
}
}
|
the_stack_data/86074462.c | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool alea(void)
{
// rand() >=0
// 0 <= ((>=0) % 2) <= 1
return rand()%2;
}
int main(void)
{
bool b1, b2, b3, b4, b5, b6, b7;
b1 = true;
b2 = false;
// b3 in 0..1 because of type? %2?
b3 = alea();
// b4 in 0..1 because logical
b4 = b1 && b3;
// b5 in 0..1 because logical
b5 = b1 || b3;
// b6 in 0..1 because logical
b6 = !b3;
// b7: xor is a bitwise operator returning an int
// it requires a special handling when both operand are boolean,
// which is not (yet) implemented
b7 = b1 ^ b2;
return 0;
}
|
the_stack_data/109415.c | // Adapted from Steve Summit's C Tutorial.
#include <ctype.h>
int myatoi(char str[]) {
int i;
int retval = 0;
for ( i = 0; str[i] != '\0'; i = i + 1 ) {
if(!isspace(str[i]))
break;
}
for ( ; str[i] != '\0'; i = i + 1 ) {
if ( !isdigit(str[i]) )
break;
retval = 10 * retval + (str[i] - '0');
}
return retval;
}
|
the_stack_data/31387418.c | #include <stdio.h>
int main (void)
{
double A, B;
int err = scanf("%lf %lf", &A, &B);
double Ans = A + B;
err = printf("%lf", Ans);
return err;
} |
the_stack_data/25136678.c | #include <stdio.h> //Cabecera
int main()
{
int edad; // Variable
printf("Introduce tu edad: ");
scanf("%d",&edad); // Lectura
if (edad >17 && edad <35)
{
printf("Tienes %d anios, eres mayor de edad",edad);
}
else if (edad < 17)
{
printf("Tienes %d anios, eres menor de edad",edad);
}
else if (edad >= 35 && edad <= 60)
{
printf("Tienes %d anios, eres adulto joven",edad);
}
else
{
printf("Tienes %d anios, eres adulto mayor \n ",edad);
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.