file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/820951.c
/* * Copyright (C) 2004 CodeSourcery, LLC * * Permission to use, copy, modify, and distribute this file * for any purpose is hereby granted without fee, provided that * the above copyright notice and this notice appears in all * copies. * * This file is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* THIS IS A COPY OF init.c FROM NEWLIB TO FIX MISSING CALL OF GLOBAL CTORS */ /* Handle ELF .{pre_init,init,fini}_array sections. */ #include <sys/types.h> #ifdef HAVE_INITFINI_ARRAY /* These magic symbols are provided by the linker. */ extern void (*__preinit_array_start []) (void) __attribute__((weak)); extern void (*__preinit_array_end []) (void) __attribute__((weak)); extern void (*__init_array_start []) (void) __attribute__((weak)); extern void (*__init_array_end []) (void) __attribute__((weak)); extern void _init (void); /* Iterate over all the init routines. */ void __libc_init_array (void) { size_t count; size_t i; count = __preinit_array_end - __preinit_array_start; for (i = 0; i < count; i++) __preinit_array_start[i] (); _init (); count = __init_array_end - __init_array_start; for (i = 0; i < count; i++) __init_array_start[i] (); } #endif
the_stack_data/986166.c
int fun(void); static int foo(void) { return ((0 || fun()) && fun()); } /* * check-name: phi-order03 * check-command: sparse -vir -flinearize=last $file */
the_stack_data/198581937.c
// Program to sort an array in ascending order. #include <stdio.h> void main() { int array[100], i, j, range; printf("Enter the range:"); scanf("%d", &range); printf("Enter %d elements for the array: \n", range); for (i = 0; i < range; i++) { scanf("%d", &array[i]); } printf("\nElements before sorting: \n"); for (i = 0; i < range; i++) { printf("%d |", array[i]); } for (i = 0; i < range; i++) { for (j = i + 1; j < range; j++) { if (array[i] > array[j]) { array[i] = array[i] + array[j]; array[j] = array[i] - array[j]; array[i] = array[i] - array[j]; } } } printf("\nElements after sorting:\n"); for (i = 0; i < range; i++) { printf("%d |", array[i]); } }
the_stack_data/15762050.c
#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> static char buf[512]; static void wc(int fd, char *name) { int i, n; int l, w, c, inword; l = w = c = 0; inword = 0; while ((n = read(fd, buf, sizeof(buf))) > 0) { for (i = 0; i < n; i++) { c++; if (buf[i] == '\n') l++; if (strchr(" \r\t\n\v", buf[i])) inword = 0; else if (!inword) { w++; inword = 1; } } } if (n < 0) { dprintf(STDERR_FILENO, "wc: read error\n"); exit(1); } dprintf(STDOUT_FILENO, "%d %d %d %s\n", l, w, c, name); } int main(int argc, char *argv[]) { int fd, i; if (argc <= 1) { wc(0, ""); exit(0); } for (i = 1; i < argc; i++) { if ((fd = open(argv[i], 0)) < 0) { dprintf(STDERR_FILENO, "wc: cannot open %s\n", argv[i]); exit(1); } wc(fd, argv[i]); close(fd); } exit(0); }
the_stack_data/22011472.c
/* { dg-do compile } */ /* { dg-options "-O -fno-strict-aliasing -fdump-tree-lim2-details" } */ void f(int * __restrict__ r, int a[__restrict__ 16][16], int b[__restrict__ 16][16], int i, int j) { int x; *r = 0; for (x = 1; x < 16; ++x) *r = *r + a[i][x] * b[x][j]; } /* We should apply store motion to the store to *r. */ /* { dg-final { scan-tree-dump "Executing store motion of \\\*r" "lim2" } } */
the_stack_data/142283.c
void partitions(int *cards, int *subtotal, int *m) { int total; // Hit for (int i = 0; i < 10; i++) { if (cards[i]>0) { cards[i] = cards[i]-1; total = subtotal[0]+i+1; if (total < 21) { // Stand m[0] += 1; // Hit again partitions(cards, &total, m); } else if (subtotal[0]+i+1==21) { // Stand; hit again is an automatic bust m[0] += 1; } cards[i] = cards[i]+1; } } }
the_stack_data/1012661.c
/* 03_pow.c */ #include <stdio.h> #include <math.h> int main() { double x, y; (void)scanf("%lf %lf", &x, &y); printf("%lf", pow(x,y)); return 0; }
the_stack_data/505427.c
#include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char const *argv[]) { int pid_button, pid_led; int button_status, led_status; pid_button = fork(); if(pid_button == 0) { //start button process char *args[] = {"./button_process", NULL}; button_status = execvp(args[0], args); printf("Error to start button process, status = %d\n", button_status); abort(); } pid_led = fork(); if(pid_led == 0) { //Start led process char *args[] = {"./led_process", NULL}; led_status = execvp(args[0], args); printf("Error to start led process, status = %d\n", led_status); abort(); } return EXIT_SUCCESS; }
the_stack_data/7950756.c
/** * Author: Simon Redman * Github: www.github.com/Sompom * Date: 20 July 2017 * * Description: These methods and test code are examples of indirect pointer * manipulation on linked lists as described here: * https://grisha.org/blog/2013/04/02/linus-on-understanding-pointers/ * * The key point about the line count is not runtime, but that the indirect * implementation has less room for bugs by removing one special case the * programmer could forget or could mess up * (Though there is a very tiny runtime speedup in the indirect case) */ #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list_entry { int value; struct list_entry* next; } list_entry_t; /** * Append to the global list by an indirect pointer * * Number of C code lines: 7 * Number of assembly instructions (GCC v4.4.7, -O2): 24 * * @param value The value to apppend * @param indirect_start Pointer to the head of the list to append to */ void append_indirect(int value, list_entry_t** indirect_start) { list_entry_t** indirect; list_entry_t* new; indirect = indirect_start; new = malloc(1 * sizeof(list_entry_t)); new->value = value; new->next = NULL; while (!(*indirect == NULL)) { indirect = &((*indirect)->next); }; *indirect = new; } /** * Append to the list using a direct pointer * * Note that direct_start is itself an indirect pointer because otherwise * we would have to play annoying games with return values * * Number of C code lines: 11 * Number of assembly instructions (GCC v4.4.7, -O2): 30 * * @param value The value to append * @param direct_start head of the list to append to */ void append_direct(int value, list_entry_t** direct_start) { list_entry_t* direct; list_entry_t* prev; list_entry_t* new; direct = *direct_start; prev = NULL; new = malloc(1 * sizeof(list_entry_t)); new->value = value; new->next = NULL; while (!(direct == NULL)) { prev = direct; direct = direct->next; } if (prev == NULL) { *direct_start = new; } else { prev->next = new; } } /** * Use a function pointer to indirect the call to append * This could also be an inline function */ void(*append)(int, void*) = (void*)append_indirect; /** * Simple main method to test that the list is sensible */ int main (int argc, char** argv) { size_t index; size_t iteration; int num_itr; int output; list_entry_t* list; list_entry_t* list_unordered; if (argc < 3) { printf("Usage:\n"); printf("First argument: String to insert into the linked list"); printf("Second argument: Number of test iterations to run"); printf("Third argument: If exists, silence output"); return -1; } num_itr = atoi(argv[2]); if (num_itr < 1) { printf("Number of iterations must be an integer greater than 0"); return -1; } output = !(argc > 3); if (output) { if (append == (void*)append_indirect) { printf("Using indirect append\n"); } else if (append == (void*)append_direct) { printf("Using direct append\n"); } } for (iteration = 0; iteration < num_itr; iteration ++) { list_unordered = NULL; for (index = 0; index < strlen(argv[1]); index ++) { append(argv[1][index] - '0', &list_unordered); } list = list_unordered; while (!(list == NULL)) { list_entry_t* prev; if (output) { printf("Iteration: %d, %p: Value: %d, Next: %p\n", iteration, list, list->value, list->next); } prev = list; list = list->next; free(prev); } } return 0; }
the_stack_data/466343.c
// RUN: %clang_cc1 -msoft-float -mfloat-abi soft -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-LE %s // RUN: %clang_cc1 -msoft-float -mfloat-abi soft -triple powerpc64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-BE %s // Test float returns and params. // CHECK: define float @func_p1(float %x) float func_p1(float x) { return x; } // CHECK: define double @func_p2(double %x) double func_p2(double x) { return x; } // CHECK: define ppc_fp128 @func_p3(ppc_fp128 %x) long double func_p3(long double x) { return x; } // Test homogeneous float aggregate passing and returning. struct f1 { float f[1]; }; struct f2 { float f[2]; }; struct f3 { float f[3]; }; struct f4 { float f[4]; }; struct f5 { float f[5]; }; struct f6 { float f[6]; }; struct f7 { float f[7]; }; struct f8 { float f[8]; }; struct f9 { float f[9]; }; struct fab { float a; float b; }; struct fabc { float a; float b; float c; }; struct f2a2b { float a[2]; float b[2]; }; // CHECK-LE: define i32 @func_f1(float inreg %x.coerce) // CHECK-BE: define void @func_f1(%struct.f1* noalias sret %agg.result, float inreg %x.coerce) struct f1 func_f1(struct f1 x) { return x; } // CHECK-LE: define i64 @func_f2(i64 %x.coerce) // CHECK-BE: define void @func_f2(%struct.f2* noalias sret %agg.result, i64 %x.coerce) struct f2 func_f2(struct f2 x) { return x; } // CHECK-LE: define { i64, i64 } @func_f3([2 x i64] %x.coerce) // CHECK-BE: define void @func_f3(%struct.f3* noalias sret %agg.result, [2 x i64] %x.coerce) struct f3 func_f3(struct f3 x) { return x; } // CHECK-LE: define { i64, i64 } @func_f4([2 x i64] %x.coerce) // CHECK-BE: define void @func_f4(%struct.f4* noalias sret %agg.result, [2 x i64] %x.coerce) struct f4 func_f4(struct f4 x) { return x; } // CHECK: define void @func_f5(%struct.f5* noalias sret %agg.result, [3 x i64] %x.coerce) struct f5 func_f5(struct f5 x) { return x; } // CHECK: define void @func_f6(%struct.f6* noalias sret %agg.result, [3 x i64] %x.coerce) struct f6 func_f6(struct f6 x) { return x; } // CHECK: define void @func_f7(%struct.f7* noalias sret %agg.result, [4 x i64] %x.coerce) struct f7 func_f7(struct f7 x) { return x; } // CHECK: define void @func_f8(%struct.f8* noalias sret %agg.result, [4 x i64] %x.coerce) struct f8 func_f8(struct f8 x) { return x; } // CHECK: define void @func_f9(%struct.f9* noalias sret %agg.result, [5 x i64] %x.coerce) struct f9 func_f9(struct f9 x) { return x; } // CHECK-LE: define i64 @func_fab(i64 %x.coerce) // CHECK-BE: define void @func_fab(%struct.fab* noalias sret %agg.result, i64 %x.coerce) struct fab func_fab(struct fab x) { return x; } // CHECK-LE: define { i64, i64 } @func_fabc([2 x i64] %x.coerce) // CHECK-BE: define void @func_fabc(%struct.fabc* noalias sret %agg.result, [2 x i64] %x.coerce) struct fabc func_fabc(struct fabc x) { return x; } // CHECK-LE: define { i64, i64 } @func_f2a2b([2 x i64] %x.coerce) // CHECK-BE: define void @func_f2a2b(%struct.f2a2b* noalias sret %agg.result, [2 x i64] %x.coerce) struct f2a2b func_f2a2b(struct f2a2b x) { return x; } // CHECK-LABEL: @call_f1 // CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f1, align 4 // CHECK: %[[TMP:[^ ]+]] = load float, float* getelementptr inbounds (%struct.f1, %struct.f1* @global_f1, i32 0, i32 0, i32 0), align 4 // CHECK-LE: call i32 @func_f1(float inreg %[[TMP]]) // CHECK-BE: call void @func_f1(%struct.f1* sret %[[TMP0]], float inreg %[[TMP]]) struct f1 global_f1; void call_f1(void) { global_f1 = func_f1(global_f1); } // CHECK-LABEL: @call_f2 // CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f2, align 4 // CHECK: %[[TMP:[^ ]+]] = load i64, i64* bitcast (%struct.f2* @global_f2 to i64*), align 4 // CHECK-LE: call i64 @func_f2(i64 %[[TMP]]) // CHECK-BE: call void @func_f2(%struct.f2* sret %[[TMP0]], i64 %[[TMP]]) struct f2 global_f2; void call_f2(void) { global_f2 = func_f2(global_f2); } // CHECK-LABEL: @call_f3 // CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f3, align 4 // CHECK: %[[TMP1:[^ ]+]] = alloca [2 x i64] // CHECK: %[[TMP2:[^ ]+]] = bitcast [2 x i64]* %[[TMP1]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[TMP2]], i8* align 4 bitcast (%struct.f3* @global_f3 to i8*), i64 12, i1 false) // CHECK: %[[TMP3:[^ ]+]] = load [2 x i64], [2 x i64]* %[[TMP1]] // CHECK-LE: call { i64, i64 } @func_f3([2 x i64] %[[TMP3]]) // CHECK-BE: call void @func_f3(%struct.f3* sret %[[TMP0]], [2 x i64] %[[TMP3]]) struct f3 global_f3; void call_f3(void) { global_f3 = func_f3(global_f3); } // CHECK-LABEL: @call_f4 // CHECK-BE: %[[TMP0:[^ ]+]] = alloca %struct.f4, align 4 // CHECK: %[[TMP:[^ ]+]] = load [2 x i64], [2 x i64]* bitcast (%struct.f4* @global_f4 to [2 x i64]*), align 4 // CHECK-LE: call { i64, i64 } @func_f4([2 x i64] %[[TMP]]) // CHECK-BE: call void @func_f4(%struct.f4* sret %[[TMP0]], [2 x i64] %[[TMP]]) struct f4 global_f4; void call_f4(void) { global_f4 = func_f4(global_f4); } // CHECK-LABEL: @call_f5 // CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f5, align 4 // CHECK: %[[TMP1:[^ ]+]] = alloca [3 x i64] // CHECK: %[[TMP2:[^ ]+]] = bitcast [3 x i64]* %[[TMP1]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[TMP2]], i8* align 4 bitcast (%struct.f5* @global_f5 to i8*), i64 20, i1 false) // CHECK: %[[TMP3:[^ ]+]] = load [3 x i64], [3 x i64]* %[[TMP1]] // CHECK: call void @func_f5(%struct.f5* sret %[[TMP0]], [3 x i64] %[[TMP3]]) struct f5 global_f5; void call_f5(void) { global_f5 = func_f5(global_f5); } // CHECK-LABEL: @call_f6 // CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f6, align 4 // CHECK: %[[TMP:[^ ]+]] = load [3 x i64], [3 x i64]* bitcast (%struct.f6* @global_f6 to [3 x i64]*), align 4 // CHECK: call void @func_f6(%struct.f6* sret %[[TMP0]], [3 x i64] %[[TMP]]) struct f6 global_f6; void call_f6(void) { global_f6 = func_f6(global_f6); } // CHECK-LABEL: @call_f7 // CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f7, align 4 // CHECK: %[[TMP1:[^ ]+]] = alloca [4 x i64], align 8 // CHECK: %[[TMP2:[^ ]+]] = bitcast [4 x i64]* %[[TMP1]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[TMP2]], i8* align 4 bitcast (%struct.f7* @global_f7 to i8*), i64 28, i1 false) // CHECK: %[[TMP3:[^ ]+]] = load [4 x i64], [4 x i64]* %[[TMP1]], align 8 // CHECK: call void @func_f7(%struct.f7* sret %[[TMP0]], [4 x i64] %[[TMP3]]) struct f7 global_f7; void call_f7(void) { global_f7 = func_f7(global_f7); } // CHECK-LABEL: @call_f8 // CHECK: %[[TMP0:[^ ]+]] = alloca %struct.f8, align 4 // CHECK: %[[TMP:[^ ]+]] = load [4 x i64], [4 x i64]* bitcast (%struct.f8* @global_f8 to [4 x i64]*), align 4 // CHECK: call void @func_f8(%struct.f8* sret %[[TMP0]], [4 x i64] %[[TMP]]) struct f8 global_f8; void call_f8(void) { global_f8 = func_f8(global_f8); } // CHECK-LABEL: @call_f9 // CHECK: %[[TMP1:[^ ]+]] = alloca [5 x i64] // CHECK: %[[TMP2:[^ ]+]] = bitcast [5 x i64]* %[[TMP1]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[TMP2]], i8* align 4 bitcast (%struct.f9* @global_f9 to i8*), i64 36, i1 false) // CHECK: %[[TMP3:[^ ]+]] = load [5 x i64], [5 x i64]* %[[TMP1]] // CHECK: call void @func_f9(%struct.f9* sret %{{[^ ]+}}, [5 x i64] %[[TMP3]]) struct f9 global_f9; void call_f9(void) { global_f9 = func_f9(global_f9); } // CHECK-LABEL: @call_fab // CHECK: %[[TMP0:[^ ]+]] = alloca %struct.fab, align 4 // CHECK: %[[TMP:[^ ]+]] = load i64, i64* bitcast (%struct.fab* @global_fab to i64*), align 4 // CHECK-LE: %call = call i64 @func_fab(i64 %[[TMP]]) // CHECK-BE: call void @func_fab(%struct.fab* sret %[[TMP0]], i64 %[[TMP]]) struct fab global_fab; void call_fab(void) { global_fab = func_fab(global_fab); } // CHECK-LABEL: @call_fabc // CHECK-BE: %[[TMPX:[^ ]+]] = alloca %struct.fabc, align 4 // CHECK: %[[TMP0:[^ ]+]] = alloca [2 x i64], align 8 // CHECK: %[[TMP2:[^ ]+]] = bitcast [2 x i64]* %[[TMP0]] to i8* // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %[[TMP2]], i8* align 4 bitcast (%struct.fabc* @global_fabc to i8*), i64 12, i1 false) // CHECK: %[[TMP3:[^ ]+]] = load [2 x i64], [2 x i64]* %[[TMP0]], align 8 // CHECK-LE: %call = call { i64, i64 } @func_fabc([2 x i64] %[[TMP3]]) // CHECK-BE: call void @func_fabc(%struct.fabc* sret %[[TMPX]], [2 x i64] %[[TMP3]]) struct fabc global_fabc; void call_fabc(void) { global_fabc = func_fabc(global_fabc); }
the_stack_data/388286.c
/* This file is part of the YAZ toolkit. * Copyright (C) Index Data * See the file LICENSE for details. */ /** * \file init_globals.c * \brief Initialize global things */ #if HAVE_CONFIG_H #include <config.h> #endif #if YAZ_POSIX_THREADS #include <pthread.h> #endif #include <errno.h> #if HAVE_GNUTLS_H #include <gnutls/gnutls.h> #endif #if HAVE_GCRYPT_H #include <gcrypt.h> #endif #if YAZ_HAVE_EXSLT #include <libexslt/exslt.h> #endif static int yaz_init_flag = 0; #if YAZ_POSIX_THREADS static pthread_mutex_t yaz_init_mutex = PTHREAD_MUTEX_INITIALIZER; #endif extern void yaz_log_init_globals(void); #if HAVE_GCRYPT_H GCRY_THREAD_OPTION_PTHREAD_IMPL; #endif void yaz_init_globals(void) { if (yaz_init_flag) return; #if YAZ_POSIX_THREADS pthread_mutex_lock(&yaz_init_mutex); #endif if (!yaz_init_flag) { yaz_log_init_globals(); #if HAVE_GCRYPT_H /* POSIX threads locking. In case gnutls_global_init do not override */ gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); #endif #if HAVE_GNUTLS_H gnutls_global_init(); #endif #if HAVE_GCRYPT_H /* most likely, GnuTLS has already initialized libgcrypt */ if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) { gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0); } #endif #if YAZ_HAVE_EXSLT exsltRegisterAll(); #endif yaz_init_flag = 1; /* must be last, before unlocking */ } #if YAZ_POSIX_THREADS pthread_mutex_unlock(&yaz_init_mutex); #endif } /* * Local variables: * c-basic-offset: 4 * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */
the_stack_data/151705064.c
#include <stdio.h> #include <stdlib.h> // Create a transient Ticket Machine Buy Tickets int menu() { int option; printf("\n===== Welcome ======== \n"); printf("\n 1. Issue a Ticket "); printf("\n 2. Check Balance "); printf("\n Please choose an option: "); scanf("%d" , &option); return option; } int main() { int op ; int amount =0 , total =0 , ticket_count = 0; void price(){ if( amount >= 90 ) { ticket_count ++; total = total + 90; printf("\n Ticket is issued. Balance to be returned is %d " , amount - 90 ); } }; do{ op = menu(); switch( op ) { case 1: printf("\n Enter amount (Cost of 1 ticket is Rs. 90) : "); scanf("%d" , &amount); price(amount); break; case 2: printf("\n Total Tickets issued: %d" , ticket_count ); printf("\n Total Money Collected: %d" , total ); break; default: printf("\n Invalid Option... Choose a correct option."); break; } }while(op != -1); return ; }
the_stack_data/22013921.c
/* 1004 成绩排名 (20 分) 解析: 1. 结构体的使用。 */ #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char name[15]; char id[15]; int score; } Student; int main(int argc, char **argv) { // 处理输入 int n; if (scanf("%d", &n) != 1) { return EXIT_FAILURE; } Student student[n], student_max = {"", "", 0}, student_min = {"", "", 100}; for (int i = 0; i < n; i++) { if (scanf("%s%s%d", student[i].name, student[i].id, &student[i].score) != 3) { return EXIT_FAILURE; } if (student[i].score >= student_max.score) { student_max = student[i]; } if (student[i].score <= student_min.score) { student_min = student[i]; } } // 处理输出 printf("%s %s\n", student_max.name, student_max.id); printf("%s %s\n", student_min.name, student_min.id); return EXIT_SUCCESS; }
the_stack_data/548470.c
/* * @explain: Copyright (c) 2020 WEI.ZHOU. All rights reserved. * The following code is only used for learning and communication, not for * illegal and commercial use. If the code is used, no consent is required, but * the author has nothing to do with any problems and consequences. * * In case of code problems, feedback can be made through the following email * address. <[email protected]> * * @Description: * 第一个数和最后一个数,第二个数与倒数第二个数交换的思想将十个数的数组逆序输出。 * @Author: WEI.ZHOU * @Date: 2020-11-14 08:56:42 * @Version: V1.0 * @Others: 推荐使用方法二 */ #include <stdio.h> int main() { int i,j,a[2][3]={{1,2},{4}}; for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) printf("%d ", a[i][j]); printf("\n"); } return 0; }
the_stack_data/1078170.c
/* Taxonomy Classification: 0000000000010000000000 */ /* * WRITE/READ 0 write * WHICH BOUND 0 upper * DATA TYPE 0 char * MEMORY LOCATION 0 stack * SCOPE 0 same * CONTAINER 0 no * POINTER 0 no * INDEX COMPLEXITY 0 constant * ADDRESS COMPLEXITY 0 constant * LENGTH COMPLEXITY 0 N/A * ADDRESS ALIAS 0 none * INDEX ALIAS 1 yes, one level * LOCAL CONTROL FLOW 0 none * SECONDARY CONTROL FLOW 0 none * LOOP STRUCTURE 0 no * LOOP COMPLEXITY 0 N/A * ASYNCHRONY 0 no * TAINT 0 no * RUNTIME ENV. DEPENDENCE 0 no * MAGNITUDE 0 no overflow * CONTINUOUS/DISCRETE 0 discrete * SIGNEDNESS 0 no */ /* Copyright 2005 Massachusetts Institute of Technology All rights reserved. Redistribution and use of software 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 set of conditions and the disclaimer below. - Redistributions in binary form must reproduce the copyright notice, this set of conditions, and the disclaimer below in the documentation and/or other materials provided with the distribution. - Neither the name of the Massachusetts Institute of Technology 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS". 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. */ int main(int argc, char *argv[]) { int i; int j; char buf[10]; i = 9; j = i; /* OK */ buf[j] = 'A'; return 0; }
the_stack_data/20023.c
//익은 토마토를 기점으로 BFS로 탐색을 하면서 0을 전부 1로 바꾼다. //-1이 있으면 건너뜀 //익을 수 있는 모든 토마토가 익으면 -1은 건너뛰고 모든 칸을 검사하고 안 익은 곳이 있으면 -1 출력 //안 익은 곳이 없으면 익은 토마토를 기점으로 최소 일 수 출력 //처음부터 다 익은 상태면 0 출력 #include <stdio.h> #define MAX 1001 #define BIG 1000001 int graph[MAX][MAX]; int visited[MAX][MAX]; int M, N, rear, front, res; typedef struct Node{ int x; int y; }q; q queue[BIG+1]; int vectX[4] = {0,0,1,-1}; int vectY[4] = {1,-1,0,0}; q dequeue() { q temp = queue[front]; front = (front + 1) % BIG; return temp; } void enqueue(int x, int y) { q temp; temp.x = x; temp.y = y; queue[rear] = temp; rear = (rear + 1) % BIG; } int BFS() { int nextX, nextY; while(front<rear) { q pop=dequeue(); for(int i=0;i<4;i++) //모든 방향으로 검사 { nextX = vectX[i] + pop.x; nextY = vectY[i] + pop.y; if(nextX>=1 && nextX<=M && nextY>=1 && nextY<=N) if(graph[nextX][nextY]==0 && !visited[nextX][nextY]) { visited[nextX][nextY] = visited[pop.x][pop.y]+1; enqueue(nextX,nextY); } } } for(int i=1; i<=M; i++) { for(int j=1; j<=N; j++) { if(visited[i][j]==0) { res=-1; return res; } else if(res<visited[i][j]) res=visited[i][j]; } } return res-1; } int main(void) { int isRipe=1; scanf("%d %d", &N, &M); for(int i=1; i<=M; i++) { for(int j=1; j<=N; j++) { scanf("%d", &graph[i][j]); if(graph[i][j]==1) { visited[i][j]=1; enqueue(i, j); } if(graph[i][j]==-1) visited[i][j]=1; } } for(int i=1; i<=M; i++) for(int j=1; j<=N; j++) if(graph[i][j]==0) isRipe=0; if(isRipe==1) printf("0\n"); else printf("%d\n",BFS()); return 0; }
the_stack_data/128592.c
#include <stdio.h> int main() { float A,r,B; scanf("%f%f",&A,&B); r=((A*3.5)+(B*7.5))/(11); printf("MEDIA = %.5f\n",r); return 0; }
the_stack_data/125139273.c
/** * * * Problems from Calculus (James Stewart) * */ #include <stdio.h> #include <math.h> typedef long double ld; static ld f19(ld x); static ld f20(ld x); static ld f21(ld x); static ld f23(ld t); static ld f24(ld p); static ld f25(ld x); static ld f26(ld t); int main(void) { ld a, b; int status, index; ld (*f[]) (ld) = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,f19,f20,f21,0,f23,f24, f25,f26 }; scanf("%i", &index); do { status = scanf("%Lf", &a); printf("Positive: %Lf\n", f[index](a)); printf("Negative: %Lf\n", f[index](-a)); } while (status); } static ld f19(ld x) { return ((x*x - 3*x) / (x*x - 9)); } static ld f20(ld x) { return f19(x); } static ld f21(ld x) { return ((sinl(x)) / (x + tanl(x))); } static ld f23(ld t) { return ((sinl(3*t)) / (tanl(2*t))); } static ld f24(ld p) { return ((1+powl(p,9)) / (1+powl(p,15))); } static ld f25(ld x) { return powl(x, x); } static ld f26(ld t) { return ((powl(5, t) - 1) / t); }
the_stack_data/234518645.c
/*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 4. Neither the name of the University 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 THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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. * * @(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95 * $FreeBSD: src/crypto/telnet/libtelnet/rsaencpwd.c,v 1.1.1.1.8.1 2002/04/13 10:59:07 markm Exp $ */ #ifdef RSA_ENCPWD /* * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION * ALL RIGHTS RESERVED * * "Digital Equipment Corporation authorizes the reproduction, * distribution and modification of this software subject to the following * restrictions: * * 1. Any partial or whole copy of this software, or any modification * thereof, must include this copyright notice in its entirety. * * 2. This software is supplied "as is" with no warranty of any kind, * expressed or implied, for any purpose, including any warranty of fitness * or merchantibility. DIGITAL assumes no responsibility for the use or * reliability of this software, nor promises to provide any form of * support for it on any basis. * * 3. Distribution of this software is authorized only if no profit or * remuneration of any kind is received in exchange for such distribution. * * 4. This software produces public key authentication certificates * bearing an expiration date established by DIGITAL and RSA Data * Security, Inc. It may cease to generate certificates after the expiration * date. Any modification of this software that changes or defeats * the expiration date or its effect is unauthorized. * * 5. Software that will renew or extend the expiration date of * authentication certificates produced by this software may be obtained * from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA * 94065, (415)595-8782, or from DIGITAL" * */ #include <sys/types.h> #include <arpa/telnet.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "encrypt.h" #include "auth.h" #include "misc.h" #include "cdc.h" extern auth_debug_mode; static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0, AUTHTYPE_RSA_ENCPWD, }; static unsigned char str_name[1024] = { IAC, SB, TELOPT_AUTHENTICATION, TELQUAL_NAME, }; #define RSA_ENCPWD_AUTH 0 /* Authentication data follows */ #define RSA_ENCPWD_REJECT 1 /* Rejected (reason might follow) */ #define RSA_ENCPWD_ACCEPT 2 /* Accepted */ #define RSA_ENCPWD_CHALLENGEKEY 3 /* Challenge and public key */ #define NAME_SZ 40 #define CHAL_SZ 20 #define PWD_SZ 40 static KTEXT_ST auth; static char name[NAME_SZ]; static char user_passwd[PWD_SZ]; static char key_file[2*NAME_SZ]; static char lhostname[NAME_SZ]; static char challenge[CHAL_SZ]; static int challenge_len; static int Data(ap, type, d, c) Authenticator *ap; int type; void *d; int c; { unsigned char *p = str_data + 4; unsigned char *cd = (unsigned char *)d; if (c == -1) c = strlen((char *)cd); if (0) { printf("%s:%d: [%d] (%d)", str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY", str_data[3], type, c); printd(d, c); printf("\r\n"); } *p++ = ap->type; *p++ = ap->way; if (type != NULL) *p++ = type; while (c-- > 0) { if ((*p++ = *cd++) == IAC) *p++ = IAC; } *p++ = IAC; *p++ = SE; if (str_data[3] == TELQUAL_IS) printsub('>', &str_data[2], p - (&str_data[2])); return(net_write(str_data, p - str_data)); } int rsaencpwd_init(ap, server) Authenticator *ap; int server; { char *cp; FILE *fp; if (server) { str_data[3] = TELQUAL_REPLY; memset(key_file, 0, sizeof(key_file)); gethostname(lhostname, sizeof(lhostname)); if ((cp = strchr(lhostname, '.')) != NULL) *cp = '\0'; strcpy(key_file, "/etc/."); strcat(key_file, lhostname); strcat(key_file, "_privkey"); if ((fp=fopen(key_file, "r"))==NULL) return(0); fclose(fp); } else { str_data[3] = TELQUAL_IS; } return(1); } int rsaencpwd_send(ap) Authenticator *ap; { printf("[ Trying RSAENCPWD ... ]\n"); if (!UserNameRequested) { return(0); } if (!auth_sendname(UserNameRequested, strlen(UserNameRequested))) { return(0); } if (!Data(ap, NULL, NULL, 0)) { return(0); } return(1); } void rsaencpwd_is(ap, data, cnt) Authenticator *ap; unsigned char *data; int cnt; { Session_Key skey; Block datablock; char r_passwd[PWD_SZ], r_user[NAME_SZ]; char *cp, key[160]; char chalkey[160], *ptr; FILE *fp; int r, i, j, chalkey_len, len; time_t now; cnt--; switch (*data++) { case RSA_ENCPWD_AUTH: memmove((void *)auth.dat, (void *)data, auth.length = cnt); if ((fp=fopen(key_file, "r"))==NULL) { Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1); auth_finished(ap, AUTH_REJECT); return; } /* * get privkey */ fscanf(fp, "%x;", &len); for (i=0;i<len;i++) { j = getc(fp); key[i]=j; } fclose(fp); r = accept_rsa_encpwd(&auth, key, challenge, challenge_len, r_passwd); if (r < 0) { Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1); auth_finished(ap, AUTH_REJECT); return; } auth_encrypt_userpwd(r_passwd); if (rsaencpwd_passwdok(UserNameRequested, UserPassword) == 0) { /* * illegal username and password */ Data(ap, RSA_ENCPWD_REJECT, (void *)"Illegal password", -1); auth_finished(ap, AUTH_REJECT); return; } Data(ap, RSA_ENCPWD_ACCEPT, (void *)0, 0); auth_finished(ap, AUTH_USER); break; case IAC: /* * If we are doing mutual authentication, get set up to send * the challenge, and verify it when the response comes back. */ if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_ONE_WAY) { register int i; time(&now); if ((now % 2) == 0) { sprintf(challenge, "%x", now); challenge_len = strlen(challenge); } else { strcpy(challenge, "randchal"); challenge_len = 8; } if ((fp=fopen(key_file, "r"))==NULL) { Data(ap, RSA_ENCPWD_REJECT, (void *)"Auth failed", -1); auth_finished(ap, AUTH_REJECT); return; } /* * skip privkey */ fscanf(fp, "%x;", &len); for (i=0;i<len;i++) { j = getc(fp); } /* * get pubkey */ fscanf(fp, "%x;", &len); for (i=0;i<len;i++) { j = getc(fp); key[i]=j; } fclose(fp); chalkey[0] = 0x30; ptr = (char *) &chalkey[1]; chalkey_len = 1+NumEncodeLengthOctets(i)+i+1+NumEncodeLengthOctets(challenge_len)+challenge_len; EncodeLength(ptr, chalkey_len); ptr +=NumEncodeLengthOctets(chalkey_len); *ptr++ = 0x04; /* OCTET STRING */ *ptr++ = challenge_len; memmove(ptr, challenge, challenge_len); ptr += challenge_len; *ptr++ = 0x04; /* OCTET STRING */ EncodeLength(ptr, i); ptr += NumEncodeLengthOctets(i); memmove(ptr, key, i); chalkey_len = 1+NumEncodeLengthOctets(chalkey_len)+chalkey_len; Data(ap, RSA_ENCPWD_CHALLENGEKEY, (void *)chalkey, chalkey_len); } break; default: Data(ap, RSA_ENCPWD_REJECT, 0, 0); break; } } void rsaencpwd_reply(ap, data, cnt) Authenticator *ap; unsigned char *data; int cnt; { Session_Key skey; KTEXT_ST token; Block enckey; int r, pubkey_len; char randchal[CHAL_SZ], *cp; char chalkey[160], pubkey[128], *ptr; if (cnt-- < 1) return; switch (*data++) { case RSA_ENCPWD_REJECT: if (cnt > 0) { printf("[ RSA_ENCPWD refuses authentication because %.*s ]\r\n", cnt, data); } else printf("[ RSA_ENCPWD refuses authentication ]\r\n"); auth_send_retry(); return; case RSA_ENCPWD_ACCEPT: printf("[ RSA_ENCPWD accepts you ]\n"); auth_finished(ap, AUTH_USER); return; case RSA_ENCPWD_CHALLENGEKEY: /* * Verify that the response to the challenge is correct. */ memmove((void *)chalkey, (void *)data, cnt); ptr = (char *) &chalkey[0]; ptr += DecodeHeaderLength(chalkey); if (*ptr != 0x04) { return; } *ptr++; challenge_len = DecodeValueLength(ptr); ptr += NumEncodeLengthOctets(challenge_len); memmove(challenge, ptr, challenge_len); ptr += challenge_len; if (*ptr != 0x04) { return; } *ptr++; pubkey_len = DecodeValueLength(ptr); ptr += NumEncodeLengthOctets(pubkey_len); memmove(pubkey, ptr, pubkey_len); memset(user_passwd, 0, sizeof(user_passwd)); local_des_read_pw_string(user_passwd, sizeof(user_passwd)-1, "Password: ", 0); UserPassword = user_passwd; Challenge = challenge; r = init_rsa_encpwd(&token, user_passwd, challenge, challenge_len, pubkey); if (r < 0) { token.length = 1; } if (!Data(ap, RSA_ENCPWD_AUTH, (void *)token.dat, token.length)) { return; } break; default: return; } } int rsaencpwd_status(ap, name, level) Authenticator *ap; char *name; int level; { if (level < AUTH_USER) return(level); if (UserNameRequested && rsaencpwd_passwdok(UserNameRequested, UserPassword)) { strcpy(name, UserNameRequested); return(AUTH_VALID); } else { return(AUTH_USER); } } #define BUMP(buf, len) while (*(buf)) {++(buf), --(len);} #define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);} void rsaencpwd_printsub(data, cnt, buf, buflen) unsigned char *data, *buf; int cnt, buflen; { char lbuf[32]; register int i; buf[buflen-1] = '\0'; /* make sure its NULL terminated */ buflen -= 1; switch(data[3]) { case RSA_ENCPWD_REJECT: /* Rejected (reason might follow) */ strncpy((char *)buf, " REJECT ", buflen); goto common; case RSA_ENCPWD_ACCEPT: /* Accepted (name might follow) */ strncpy((char *)buf, " ACCEPT ", buflen); common: BUMP(buf, buflen); if (cnt <= 4) break; ADDC(buf, buflen, '"'); for (i = 4; i < cnt; i++) ADDC(buf, buflen, data[i]); ADDC(buf, buflen, '"'); ADDC(buf, buflen, '\0'); break; case RSA_ENCPWD_AUTH: /* Authentication data follows */ strncpy((char *)buf, " AUTH", buflen); goto common2; case RSA_ENCPWD_CHALLENGEKEY: strncpy((char *)buf, " CHALLENGEKEY", buflen); goto common2; default: sprintf(lbuf, " %d (unknown)", data[3]); strncpy((char *)buf, lbuf, buflen); common2: BUMP(buf, buflen); for (i = 4; i < cnt; i++) { sprintf(lbuf, " %d", data[i]); strncpy((char *)buf, lbuf, buflen); BUMP(buf, buflen); } break; } } int rsaencpwd_passwdok(name, passwd) char *name, *passwd; { char *crypt(); char *salt, *p; struct passwd *pwd; int passwdok_status = 0; if (pwd = getpwnam(name)) salt = pwd->pw_passwd; else salt = "xx"; p = crypt(passwd, salt); if (pwd && !strcmp(p, pwd->pw_passwd)) { passwdok_status = 1; } else passwdok_status = 0; return(passwdok_status); } #endif
the_stack_data/103265074.c
void bar1() {} void bar2(double x) {} void foo() { double val; { /* bar1() is inlined below */ #pragma spf assert nomacro {} /* bar2(val) is inlined below */ #pragma spf assert nomacro { double x1 = val; } } } void foo1() { /* foo() is inlined below */ #pragma spf assert nomacro { double val; { /* bar1() is inlined below */ #pragma spf assert nomacro {} /* bar2(val) is inlined below */ #pragma spf assert nomacro { double x0 = val; } } } }
the_stack_data/136756.c
/** ****************************************************************************** * @file ultraviolet-sensor.c * @author * @version V1.0.0 * @date 08-August-2017 * @brief Enable UV sensor functionality ****************************************************************************** * @attention * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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. * ****************************************************************************** */ /** * @defgroup ultraviolet_sensor * @ingroup dev * @{ */ /** * @addtogroup ultraviolet_sensor * @ingroup dev * @{ * @file Driver for the UV sensor (on expansion board) */ /*---------------------------------------------------------------------------*/ #if COMPILE_SENSORS /*---------------------------------------------------------------------------*/ #include "lib/sensors.h" #include "ultraviolet-sensor.h" #include "st-lib.h" /*---------------------------------------------------------------------------*/ static int _active = 0; static void *ultraviolet_handle = NULL; /*---------------------------------------------------------------------------*/ static void init(void) { #ifdef USE_IKS01A2 if (COMPONENT_ERROR == st_lib_bsp_ultraviolet_init(ULTRAVIOLET_SENSORS_AUTO, &ultraviolet_handle)){ printf("ERROR initializing UV Sensor\n"); } #else if (COMPONENT_ERROR == st_lib_bsp_ultraviolet_init(VEML6075_0, &ultraviolet_handle)){ printf("ERROR initializing Humidity Sensor\n"); } #endif } /*---------------------------------------------------------------------------*/ static void activate(void) { if (st_lib_bsp_ultraviolet_sensor_enable(ultraviolet_handle) ==COMPONENT_OK){ _active=1; } } /*---------------------------------------------------------------------------*/ static void deactivate(void) { if (st_lib_bsp_ultraviolet_sensor_disable(ultraviolet_handle) ==COMPONENT_OK){ _active=0; } } /*---------------------------------------------------------------------------*/ static int active(void) { return _active; } /*---------------------------------------------------------------------------*/ static int value(int type) { uint32_t ultraviolet; volatile uint16_t ultraviolet_value; uint8_t status = 0; if (st_lib_bsp_ultraviolet_is_initialized(ultraviolet_handle, &status) == COMPONENT_OK && status == 1){ st_lib_bsp_ultraviolet_get_uv(ultraviolet_handle, (uint16_t *) &ultraviolet_value); } ultraviolet = ultraviolet_value; return ultraviolet; } /*---------------------------------------------------------------------------*/ static int configure(int type, int value) { switch(type) { case SENSORS_HW_INIT: init(); return 1; case SENSORS_ACTIVE: if(value) { activate(); } else { deactivate(); } return 1; } return 0; } /*---------------------------------------------------------------------------*/ static int status(int type) { switch(type) { case SENSORS_READY: return active(); } return 0; } /*---------------------------------------------------------------------------*/ SENSORS_SENSOR(ultraviolet_sensor, ULTRAVIOLET_SENSOR, value, configure, status); /*---------------------------------------------------------------------------*/ #endif /*COMPILE_SENSORS*/ /*---------------------------------------------------------------------------*/ /** @} */ /** @} */
the_stack_data/111010.c
/* getenv( const char * ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ /* This is a stub implementation of getenv */ #include <string.h> #include <stdlib.h> #ifndef REGTEST char* getenv(const char* name) { return NULL; } #endif #ifdef TEST #include "_PDCLIB_test.h" int main(void) { return TEST_RESULTS; } #endif
the_stack_data/150144445.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2016-2021 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ int function (int arg) { return arg + 1; } void inner (void) { } void outer (void) { inner (); } int main (void) { int i, j; for (i = 0, j = 0; i < 100; ++i) j = function (j); outer (); return j; }
the_stack_data/212644442.c
/* * refclock_jjy - clock driver for JJY receivers */ /**********************************************************************/ /* */ /* Copyright (C) 2001, Takao Abe. All rights reserved. */ /* */ /* Permission to use, copy, modify, and distribute this software */ /* and its documentation for any purpose is hereby granted */ /* without fee, provided that the following conditions are met: */ /* */ /* One retains the entire copyright notice properly, and both the */ /* copyright notice and this license. in the documentation and/or */ /* other materials provided with the distribution. */ /* */ /* This software and the name of the author must not be used to */ /* endorse or promote products derived from this software without */ /* prior written permission. */ /* */ /* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESSED OR IMPLIED */ /* WARRANTIES OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, THE */ /* IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS FOR A */ /* PARTICULAR PURPOSE. */ /* IN NO EVENT SHALL THE AUTHOR TAKAO ABE BE LIABLE FOR ANY DIRECT, */ /* INDIRECT, GENERAL, 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. */ /* */ /* This driver is developed in my private time, and is opened as */ /* voluntary contributions for the NTP. */ /* The manufacturer of the JJY receiver has not participated in */ /* a development of this driver. */ /* The manufacturer does not warrant anything about this driver, */ /* and is not liable for anything about this driver. */ /* */ /**********************************************************************/ /* */ /* Author Takao Abe */ /* Email [email protected] */ /* Homepage http://www.bea.hi-ho.ne.jp/abetakao/ */ /* */ /**********************************************************************/ /* */ /* History */ /* */ /* 2001/07/15 */ /* [New] Support the Tristate Ltd. JJY receiver */ /* */ /* 2001/08/04 */ /* [Change] Log to clockstats even if bad reply */ /* [Fix] PRECISION = (-3) (about 100 ms) */ /* [Add] Support the C-DEX Co.Ltd. JJY receiver */ /* 2001/12/04 */ /* [Fix] C-DEX JST2000 ( [email protected] ) */ /* */ /**********************************************************************/ #ifdef HAVE_CONFIG_H #include <config.h> #endif #if defined(REFCLOCK) && defined(CLOCK_JJY) #include <stdio.h> #include <ctype.h> #include <string.h> #include <sys/time.h> #include <time.h> #include "ntpd.h" #include "ntp_io.h" #include "ntp_tty.h" #include "ntp_refclock.h" #include "ntp_calendar.h" #include "ntp_stdlib.h" /**********************************************************************/ /* */ /* The Tristate Ltd. JJY receiver JJY01 */ /* */ /* Command Response Remarks */ /* ------------ ---------------------- --------------------- */ /* date<CR><LF> YYYY/MM/DD XXX<CR><LF> */ /* time<CR><LF> HH:MM:SS<CR><LF> */ /* stim<CR><LF> HH:MM:SS<CR><LF> Reply at just second */ /* */ /* During synchronization after a receiver is turned on, */ /* It replies the past time from 2000/01/01 00:00:00. */ /* The function "refclock_process" checks the time and tells */ /* as an insanity time. */ /* */ /**********************************************************************/ /* */ /* The C-DEX Co. Ltd. JJY receiver JST2000 */ /* */ /* Command Response Remarks */ /* ------------ ---------------------- --------------------- */ /* <ENQ>1J<ETX> <STX>JYYMMDD HHMMSSS<ETX> */ /* */ /**********************************************************************/ /* * Interface definitions */ #define DEVICE "/dev/jjy%d" /* device name and unit */ #define SPEED232 B9600 /* uart speed (9600 baud) */ #define REFID "JJY" /* reference ID */ #define DESCRIPTION "JJY Receiver" #define PRECISION (-3) /* precision assumed (about 100 ms) */ /* * JJY unit control structure */ struct jjyunit { char unittype ; /* UNITTYPE_XXXXXXXXXX */ short version ; short linediscipline ; /* LDISC_CLK or LDISC_RAW */ int linecount ; int lineerror ; int year, month, day, hour, minute, second, msecond ; /* LDISC_RAW only */ #define MAX_LINECOUNT 8 #define MAX_RAWBUF 64 int lineexpect ; int charexpect [ MAX_LINECOUNT ] ; int charcount ; char rawbuf [ MAX_RAWBUF ] ; }; #define UNITTYPE_TRISTATE_JJY01 1 #define UNITTYPE_CDEX_JST2000 2 /* * Function prototypes */ static int jjy_start P((int, struct peer *)); static void jjy_shutdown P((int, struct peer *)); static void jjy_poll P((int, struct peer *)); static void jjy_poll_tristate_jjy01 P((int, struct peer *)); static void jjy_poll_cdex_jst2000 P((int, struct peer *)); static void jjy_receive P((struct recvbuf *)); static int jjy_receive_tristate_jjy01 P((struct recvbuf *)); static int jjy_receive_cdex_jst2000 P((struct recvbuf *)); /* * Transfer vector */ struct refclock refclock_jjy = { jjy_start, /* start up driver */ jjy_shutdown, /* shutdown driver */ jjy_poll, /* transmit poll message */ noentry, /* not used */ noentry, /* not used */ noentry, /* not used */ NOFLAGS /* not used */ }; /* * Start up driver return code */ #define RC_START_SUCCESS 1 #define RC_START_ERROR 0 /* * Local constants definition */ #define MAX_LOGTEXT 64 /**************************************************************************************************/ /* jjy_start - open the devices and initialize data for processing */ /**************************************************************************************************/ static int jjy_start ( int unit, struct peer *peer ) { struct jjyunit *up ; struct refclockproc *pp ; int fd ; char *pDeviceName ; short iDiscipline ; #ifdef DEBUG if ( debug ) { printf ( "jjy_start (refclock_jjy.c) : %s mode=%d ", ntoa(&peer->srcadr), peer->ttlmax ) ; printf ( DEVICE, unit ) ; printf ( "\n" ) ; } #endif /* * Open serial port */ if ( ! ( pDeviceName = (char*) emalloc ( strlen(DEVICE) + 10 ) ) ) { return RC_START_ERROR ; } sprintf ( pDeviceName, DEVICE, unit ) ; /* * peer->ttlmax is a mode number specified by "127.127.40.X mode N" in the ntp.conf */ switch ( peer->ttlmax ) { case 0 : case 1 : iDiscipline = LDISC_CLK ; break ; case 2 : iDiscipline = LDISC_RAW ; break ; default : msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode", ntoa(&peer->srcadr), peer->ttlmax ) ; free ( (void*) pDeviceName ) ; return RC_START_ERROR ; } if ( ! ( fd = refclock_open ( pDeviceName, SPEED232, iDiscipline ) ) ) { free ( (void*) pDeviceName ) ; return RC_START_ERROR ; } free ( (void*) pDeviceName ) ; /* * Allocate and initialize unit structure */ if ( ! ( up = (struct jjyunit *) emalloc (sizeof(struct jjyunit)) ) ) { close ( fd ) ; return RC_START_ERROR ; } memset ( (char*)up, 0, sizeof(struct jjyunit) ) ; up->linediscipline = iDiscipline ; /* * peer->ttlmax is a mode number specified by "127.127.40.X mode N" in the ntp.conf */ switch ( peer->ttlmax ) { case 0 : /* * The mode 0 is a default clock type at this time. * But this will be change to auto-detect mode in the future. */ case 1 : up->unittype = UNITTYPE_TRISTATE_JJY01 ; up->version = 100 ; up->lineexpect = 2 ; up->charexpect[0] = 14 ; /* YYYY/MM/DD WWW<CR><LF> */ up->charexpect[1] = 8 ; /* HH:MM:SS<CR><LF> */ break ; case 2 : up->unittype = UNITTYPE_CDEX_JST2000 ; up->lineexpect = 1 ; up->charexpect[0] = 15 ; /* <STX>JYYMMDD HHMMSSS<ETX> */ break ; default : msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode", ntoa(&peer->srcadr), peer->ttlmax ) ; close ( fd ) ; free ( (void*) up ) ; return RC_START_ERROR ; } pp = peer->procptr ; pp->unitptr = (caddr_t) up ; pp->io.clock_recv = jjy_receive ; pp->io.srcclock = (caddr_t) peer ; pp->io.datalen = 0 ; pp->io.fd = fd ; if ( ! io_addclock(&pp->io) ) { close ( fd ) ; free ( (void*) up ) ; return RC_START_ERROR ; } /* * Initialize miscellaneous variables */ peer->precision = PRECISION ; peer->burst = 1 ; pp->clockdesc = DESCRIPTION ; memcpy ( (char*)&pp->refid, REFID, strlen(REFID) ) ; return RC_START_SUCCESS ; } /**************************************************************************************************/ /* jjy_shutdown - shutdown the clock */ /**************************************************************************************************/ static void jjy_shutdown ( int unit, struct peer *peer ) { struct jjyunit *up; struct refclockproc *pp; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; io_closeclock ( &pp->io ) ; free ( (void*) up ) ; } /**************************************************************************************************/ /* jjy_receive - receive data from the serial interface */ /**************************************************************************************************/ static void jjy_receive ( struct recvbuf *rbufp ) { struct jjyunit *up ; struct refclockproc *pp ; struct peer *peer; l_fp tRecvTimestamp; /* arrival timestamp */ int rc ; char sLogText [ MAX_LOGTEXT ] ; int i, bCntrlChar ; /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *) rbufp->recv_srcclock ; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; /* * Get next input line */ pp->lencode = refclock_gtlin ( rbufp, pp->a_lastcode, BMAX, &tRecvTimestamp ) ; if ( up->linediscipline == LDISC_RAW ) { /* * The reply with <STX> and <ETX> may give a blank line */ if ( pp->lencode == 0 && up->charcount == 0 ) return ; /* * Copy received charaters to temporary buffer */ for ( i = 0 ; i < pp->lencode && up->charcount < MAX_RAWBUF - 2 ; i ++ , up->charcount ++ ) { up->rawbuf[up->charcount] = pp->a_lastcode[i] ; } while ( up->charcount > 0 && up->rawbuf[0] < ' ' ) { for ( i = 0 ; i < up->charcount - 1 ; i ++ ) up->rawbuf[i] = up->rawbuf[i+1] ; up->charcount -- ; } bCntrlChar = 0 ; for ( i = 0 ; i < up->charcount ; i ++ ) { if ( up->rawbuf[i] < ' ' ) { bCntrlChar = 1 ; break ; } } if ( pp->lencode > 0 && up->linecount < up->lineexpect ) { if ( bCntrlChar == 0 && up->charcount < up->charexpect[up->linecount] ) return ; } up->rawbuf[up->charcount] = 0 ; } else { /* * The reply with <CR><LF> gives a blank line */ if ( pp->lencode == 0 ) return ; } /* * We get down to business */ pp->lastrec = tRecvTimestamp ; up->linecount ++ ; if ( up->lineerror != 0 ) return ; switch ( up->unittype ) { case UNITTYPE_TRISTATE_JJY01 : rc = jjy_receive_tristate_jjy01 ( rbufp ) ; break ; case UNITTYPE_CDEX_JST2000 : rc = jjy_receive_cdex_jst2000 ( rbufp ) ; break ; default : rc = 0 ; break ; } if ( up->linediscipline == LDISC_RAW ) { if ( up->linecount <= up->lineexpect && up->charcount > up->charexpect[up->linecount-1] ) { for ( i = 0 ; i < up->charcount - up->charexpect[up->linecount-1] ; i ++ ) { up->rawbuf[i] = up->rawbuf[i+up->charexpect[up->linecount-1]] ; } up->charcount -= up->charexpect[up->linecount-1] ; } else { up->charcount = 0 ; } } if ( rc == 0 ) return ; if ( up->lineerror != 0 ) { refclock_report ( peer, CEVNT_BADREPLY ) ; strcpy ( sLogText, "BAD REPLY [" ) ; if ( up->linediscipline == LDISC_RAW ) { strncat ( sLogText, up->rawbuf, MAX_LOGTEXT - strlen ( sLogText ) - 1 ) ; } else { strncat ( sLogText, pp->a_lastcode, MAX_LOGTEXT - strlen ( sLogText ) - 1 ) ; } sLogText[MAX_LOGTEXT-1] = 0 ; if ( strlen ( sLogText ) < MAX_LOGTEXT - 2 ) strcat ( sLogText, "]" ) ; record_clock_stats ( &peer->srcadr, sLogText ) ; return ; } pp->year = up->year ; pp->day = ymd2yd ( up->year, up->month, up->day ) ; pp->hour = up->hour ; pp->minute = up->minute ; pp->second = up->second ; pp->msec = up->msecond ; pp->usec = 0; /* * JST to UTC */ pp->hour -= 9 ; if ( pp->hour < 0 ) { pp->hour += 24 ; pp->day -- ; if ( pp->day < 1 ) { pp->year -- ; pp->day = ymd2yd ( pp->year, 12, 31 ) ; } } #ifdef DEBUG if ( debug ) { printf ( "jjy_receive (refclock_jjy.c) : %04d/%02d/%02d %02d:%02d:%02d JST ", up->year, up->month, up->day, up->hour, up->minute, up->second ) ; printf ( "( %04d/%03d %02d:%02d:%02d UTC )\n", pp->year, pp->day, pp->hour, pp->minute, pp->second ) ; } #endif /* * Process the new sample in the median filter and determine the * timecode timestamp. */ if ( ! refclock_process ( pp ) ) { refclock_report(peer, CEVNT_BADTIME); sprintf ( sLogText, "BAD TIME %04d/%02d/%02d %02d:%02d:%02d JST", up->year, up->month, up->day, up->hour, up->minute, up->second ) ; record_clock_stats ( &peer->srcadr, sLogText ) ; return ; } sprintf ( sLogText, "%04d/%02d/%02d %02d:%02d:%02d JST", up->year, up->month, up->day, up->hour, up->minute, up->second ) ; record_clock_stats ( &peer->srcadr, sLogText ) ; refclock_receive(peer); } /**************************************************************************************************/ static int jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ) { struct jjyunit *up ; struct refclockproc *pp ; struct peer *peer; char *pBuf ; int iLen ; int rc ; /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *) rbufp->recv_srcclock ; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; if ( up->linediscipline == LDISC_RAW ) { pBuf = up->rawbuf ; iLen = up->charcount ; } else { pBuf = pp->a_lastcode ; iLen = pp->lencode ; } switch ( up->linecount ) { case 1 : /* YYYY/MM/DD */ if ( iLen < 10 ) { up->lineerror = 1 ; break ; } rc = sscanf ( pBuf, "%4d/%2d/%2d", &up->year, &up->month, &up->day ) ; if ( rc != 3 || up->year < 2000 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 ) { up->lineerror = 1 ; break ; } return 0 ; case 2 : /* HH:MM:SS */ if ( iLen < 8 ) { up->lineerror = 1 ; break ; } rc = sscanf ( pBuf, "%2d:%2d:%2d", &up->hour, &up->minute, &up->second ) ; if ( rc != 3 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { up->lineerror = 1 ; break ; } up->msecond = 0 ; if ( up->hour == 0 && up->minute == 0 && up->second <= 2 ) { /* * The command "date" and "time" ( or "stim" ) were sent to the JJY receiver continuously. * But the JJY receiver replies a date and time separately. * Just after midnight transtions, we ignore this time. */ return 0 ; } break ; default : /* Unexpected reply */ up->lineerror = 1 ; break ; } return 1 ; } /**************************************************************************************************/ static int jjy_receive_cdex_jst2000 ( struct recvbuf *rbufp ) { struct jjyunit *up ; struct refclockproc *pp ; struct peer *peer; char *pBuf ; int iLen ; int rc ; /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *) rbufp->recv_srcclock ; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; if ( up->linediscipline == LDISC_RAW ) { pBuf = up->rawbuf ; iLen = up->charcount ; } else { pBuf = pp->a_lastcode ; iLen = pp->lencode ; } switch ( up->linecount ) { case 1 : /* JYYMMDD HHMMSSS */ if ( iLen < 15 ) { up->lineerror = 1 ; break ; } rc = sscanf ( pBuf, "J%2d%2d%2d%*1d%2d%2d%2d%1d", &up->year, &up->month, &up->day, &up->hour, &up->minute, &up->second, &up->msecond ) ; if ( rc != 7 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { up->lineerror = 1 ; break ; } up->year += 2000 ; up->msecond *= 100 ; break ; default : /* Unexpected reply */ up->lineerror = 1 ; break ; } return 1 ; } /**************************************************************************************************/ /* jjy_poll - called by the transmit procedure */ /**************************************************************************************************/ static void jjy_poll ( int unit, struct peer *peer ) { struct jjyunit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct jjyunit *) pp->unitptr ; if ( pp->polls > 0 && up->linecount == 0 ) { /* * No reply for last command */ refclock_report ( peer, CEVNT_TIMEOUT ) ; } #ifdef DEBUG if ( debug ) { printf ( "jjy_poll (refclock_jjy.c) : %ld\n", pp->polls ) ; } #endif pp->polls ++ ; up->linecount = 0 ; up->lineerror = 0 ; up->charcount = 0 ; switch ( up->unittype ) { case UNITTYPE_TRISTATE_JJY01 : jjy_poll_tristate_jjy01 ( unit, peer ) ; break ; case UNITTYPE_CDEX_JST2000 : jjy_poll_cdex_jst2000 ( unit, peer ) ; break ; default : break ; } } /**************************************************************************************************/ static void jjy_poll_tristate_jjy01 ( int unit, struct peer *peer ) { struct jjyunit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct jjyunit *) pp->unitptr ; /* * Send "date<CR><LF>" command */ if ( write ( pp->io.fd, "date\r\n",6 ) != 6 ) { refclock_report ( peer, CEVNT_FAULT ) ; } /* * Send "stim<CR><LF>" or "time<CR><LF>" command */ if ( up->version >= 100 ) { if ( write ( pp->io.fd, "stim\r\n",6 ) != 6 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } else { if ( write ( pp->io.fd, "time\r\n",6 ) != 6 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } } /**************************************************************************************************/ static void jjy_poll_cdex_jst2000 ( int unit, struct peer *peer ) { struct refclockproc *pp; pp = peer->procptr; /* * Send "<ENQ>1J<ETX>" command */ if ( write ( pp->io.fd, "\x051J\x03", 4 ) != 4 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } #else int refclock_jjy_bs ; #endif /* REFCLOCK */
the_stack_data/110398.c
/** Generated from source: file:///Users/sradomski/Documents/TK/Code/uscxml/test/w3c/lua/test240.scxml */ #ifndef USCXML_NO_STDTYPES_H # include <stdint.h> /* explicit types */ #endif #include <stddef.h> /* NULL */ #ifndef USCXML_NO_GEN_C_MACROS /** * All macros used for the scxml types and functions * * ** IMPORTANT: Make sure to set the following macros prior to including. ** * They are used to represent the machine in the types to follow * and to allocate stack memory during a micro-step function. * When in doubt, overprovide. * * USCXML_NR_STATES_TYPE * as the smallest type for positive integers that can contain the * largest number of states from an individual state machine. E.g.: * < 2^8 states => uint8_t * < 2^16 states => uint16_t * < 2^32 states => uint32_t */ #ifndef USCXML_NR_STATES_TYPE # define USCXML_NR_STATES_TYPE uint8_t #endif /** * USCXML_NR_TRANS_TYPE * the same as above but for the number of transitions. */ #ifndef USCXML_NR_TRANS_TYPE # define USCXML_NR_TRANS_TYPE uint8_t #endif /** * USCXML_MAX_NR_STATES_BYTES * the smallest multiple of 8 that, if multiplied by 8, * is larger than USCXML_NR_STATES_TYPE, e.g: * 1-8 states => 1 * 9-16 states => 2 * 17-24 states => 3 * 25-32 states => 4 * ... */ #ifndef USCXML_MAX_NR_STATES_BYTES # define USCXML_MAX_NR_STATES_BYTES 1 #endif /** * USCXML_MAX_NR_TRANS_BYTES * same as above but for transitions. */ #ifndef USCXML_MAX_NR_TRANS_BYTES # define USCXML_MAX_NR_TRANS_BYTES 1 #endif /** * USCXML_NUMBER_STATES / USCXML_NUMBER_TRANS * Per default the number of states / transitions is retrieved from the machine * info in the uscxml_ctx struct, but you can also hard-code it per macro. */ #ifndef USCXML_NUMBER_STATES # define USCXML_NUMBER_STATES (ctx->machine->nr_states) #endif #ifndef USCXML_NUMBER_TRANS # define USCXML_NUMBER_TRANS (ctx->machine->nr_transitions) #endif /** * USCXML_GET_STATE / USCXML_GET_TRANS * Per default an individual state or transitions is retrieved from the machine * info in the uscxml_ctx struct, but you can also hard-code it per macro. */ #ifndef USCXML_GET_STATE # define USCXML_GET_STATE(i) (ctx->machine->states[i]) #endif #ifndef USCXML_GET_TRANS # define USCXML_GET_TRANS(i) (ctx->machine->transitions[i]) #endif /* Common macros below */ #define BIT_HAS(idx, bitset) ((bitset[idx >> 3] & (1 << (idx & 7))) != 0) #define BIT_SET_AT(idx, bitset) bitset[idx >> 3] |= (1 << (idx & 7)); #define BIT_CLEAR(idx, bitset) bitset[idx >> 3] &= (1 << (idx & 7)) ^ 0xFF; #ifdef __GNUC__ # define likely(x) (__builtin_expect(!!(x), 1)) # define unlikely(x) (__builtin_expect(!!(x), 0)) #else # define likely(x) (x) # define unlikely(x) (x) #endif /* error return codes */ #define USCXML_ERR_OK 0 #define USCXML_ERR_IDLE 1 #define USCXML_ERR_DONE 2 #define USCXML_ERR_MISSING_CALLBACK 3 #define USCXML_ERR_FOREACH_DONE 4 #define USCXML_ERR_EXEC_CONTENT 5 #define USCXML_ERR_INVALID_TARGET 6 #define USCXML_ERR_INVALID_TYPE 7 #define USCXML_ERR_UNSUPPORTED 8 #define USCXML_TRANS_SPONTANEOUS 0x01 #define USCXML_TRANS_TARGETLESS 0x02 #define USCXML_TRANS_INTERNAL 0x04 #define USCXML_TRANS_HISTORY 0x08 #define USCXML_TRANS_INITIAL 0x10 #define USCXML_STATE_ATOMIC 0x01 #define USCXML_STATE_PARALLEL 0x02 #define USCXML_STATE_COMPOUND 0x03 #define USCXML_STATE_FINAL 0x04 #define USCXML_STATE_HISTORY_DEEP 0x05 #define USCXML_STATE_HISTORY_SHALLOW 0x06 #define USCXML_STATE_INITIAL 0x07 #define USCXML_STATE_HAS_HISTORY 0x80 /* highest bit */ #define USCXML_STATE_MASK(t) (t & 0x7F) /* mask highest bit */ #define USCXML_CTX_PRISTINE 0x00 #define USCXML_CTX_SPONTANEOUS 0x01 #define USCXML_CTX_INITIALIZED 0x02 #define USCXML_CTX_TOP_LEVEL_FINAL 0x04 #define USCXML_CTX_TRANSITION_FOUND 0x08 #define USCXML_CTX_FINISHED 0x10 #define USCXML_ELEM_DATA_IS_SET(data) (data->id != NULL) #define USCXML_ELEM_DONEDATA_IS_SET(donedata) (donedata->content != NULL || donedata->contentexpr != NULL || donedata->params != NULL) #define USCXML_ELEM_PARAM_IS_SET(param) (param->name != NULL) #define USCXML_MACHINE_IS_SET(machine) (machine->nr_states > 0) #define USCXML_NO_GEN_C_MACROS #endif #ifndef USCXML_NO_GEN_C_TYPES /** * All types required to represent an SCXML state chart. * Just predefine the USCXML_NO_GEN_C_TYPES macro if you do not need them. */ typedef struct uscxml_machine uscxml_machine; typedef struct uscxml_transition uscxml_transition; typedef struct uscxml_state uscxml_state; typedef struct uscxml_ctx uscxml_ctx; typedef struct uscxml_elem_invoke uscxml_elem_invoke; typedef struct uscxml_elem_send uscxml_elem_send; typedef struct uscxml_elem_param uscxml_elem_param; typedef struct uscxml_elem_data uscxml_elem_data; typedef struct uscxml_elem_assign uscxml_elem_assign; typedef struct uscxml_elem_donedata uscxml_elem_donedata; typedef struct uscxml_elem_foreach uscxml_elem_foreach; typedef void* (*dequeue_internal_t)(const uscxml_ctx* ctx); typedef void* (*dequeue_external_t)(const uscxml_ctx* ctx); typedef int (*is_enabled_t)(const uscxml_ctx* ctx, const uscxml_transition* transition); typedef int (*is_matched_t)(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event); typedef int (*is_true_t)(const uscxml_ctx* ctx, const char* expr); typedef int (*exec_content_t)(const uscxml_ctx* ctx, const uscxml_state* state, const void* event); typedef int (*raise_done_event_t)(const uscxml_ctx* ctx, const uscxml_state* state, const uscxml_elem_donedata* donedata); typedef int (*invoke_t)(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke); typedef int (*exec_content_log_t)(const uscxml_ctx* ctx, const char* label, const char* expr); typedef int (*exec_content_raise_t)(const uscxml_ctx* ctx, const char* event); typedef int (*exec_content_send_t)(const uscxml_ctx* ctx, const uscxml_elem_send* send); typedef int (*exec_content_foreach_init_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_foreach_next_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_foreach_done_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_assign_t)(const uscxml_ctx* ctx, const uscxml_elem_assign* assign); typedef int (*exec_content_init_t)(const uscxml_ctx* ctx, const uscxml_elem_data* data); typedef int (*exec_content_cancel_t)(const uscxml_ctx* ctx, const char* sendid, const char* sendidexpr); typedef int (*exec_content_finalize_t)(const uscxml_ctx* ctx, const uscxml_elem_invoke* invoker, const void* event); typedef int (*exec_content_script_t)(const uscxml_ctx* ctx, const char* src, const char* content); /** * A single SCXML state-machine. */ struct uscxml_machine { unsigned char flags; /* Unused */ USCXML_NR_STATES_TYPE nr_states; /* Make sure to set type per macro! */ USCXML_NR_TRANS_TYPE nr_transitions; /* Make sure to set type per macro! */ const char* name; const char* datamodel; const char* uuid; /* currently MD5 sum */ const uscxml_state* states; const uscxml_transition* transitions; const uscxml_machine* parent; const uscxml_elem_donedata* donedata; const exec_content_t script; /* Global script elements */ }; /** * All information pertaining to a <data> element * With late data binding, blocks of data elements are separated by NULL * use USCXML_ELEM_DATA_IS_SET to test for end of a block. */ struct uscxml_elem_data { const char* id; const char* src; const char* expr; const char* content; }; /** * All information pertaining to an <assign> element */ struct uscxml_elem_assign { const char* location; const char* expr; const char* content; }; /** * All information pertaining to any state element */ struct uscxml_state { const char* name; /* eventual name */ const USCXML_NR_STATES_TYPE parent; /* parent */ const exec_content_t on_entry; /* on entry handlers */ const exec_content_t on_exit; /* on exit handlers */ const invoke_t invoke; /* invocations */ const unsigned char children[USCXML_MAX_NR_STATES_BYTES]; /* all children */ const unsigned char completion[USCXML_MAX_NR_STATES_BYTES]; /* default completion */ const unsigned char ancestors[USCXML_MAX_NR_STATES_BYTES]; /* all ancestors */ const uscxml_elem_data* data; /* data with late binding */ const unsigned char type; /* One of USCXML_STATE_* */ }; /** * All information pertaining to a <transition> element */ struct uscxml_transition { const USCXML_NR_STATES_TYPE source; const unsigned char target[USCXML_MAX_NR_STATES_BYTES]; const char* event; const char* condition; const is_enabled_t is_enabled; const exec_content_t on_transition; const unsigned char type; const unsigned char conflicts[USCXML_MAX_NR_TRANS_BYTES]; const unsigned char exit_set[USCXML_MAX_NR_STATES_BYTES]; }; /** * All information pertaining to a <foreach> element */ struct uscxml_elem_foreach { const char* array; const char* item; const char* index; }; /** * All information pertaining to a <param> element * Blocks of params are separated by NULL params, use * USCXML_ELEM_PARAM_IS_SET to test for end of a block. */ struct uscxml_elem_param { const char* name; const char* expr; const char* location; }; /** * All information pertaining to a <donedata> element */ struct uscxml_elem_donedata { const USCXML_NR_STATES_TYPE source; const char* content; const char* contentexpr; const uscxml_elem_param* params; }; /** * All information pertaining to an <invoke> element */ struct uscxml_elem_invoke { const uscxml_machine* machine; const char* type; const char* typeexpr; const char* src; const char* srcexpr; const char* id; const char* idlocation; const char* sourcename; const char* namelist; const unsigned char autoforward; const uscxml_elem_param* params; exec_content_finalize_t finalize; const char* content; const char* contentexpr; }; /** * All information pertaining to a <send> element */ struct uscxml_elem_send { const char* event; const char* eventexpr; const char* target; const char* targetexpr; const char* type; const char* typeexpr; const char* id; const char* idlocation; unsigned long delay; const char* delayexpr; const char* namelist; /* not space-separated, still as in attribute value */ const char* content; const char* contentexpr; const uscxml_elem_param* params; }; /** * Represents an instance of a state-chart at runtime/ */ struct uscxml_ctx { unsigned char flags; const uscxml_machine* machine; unsigned char config[USCXML_MAX_NR_STATES_BYTES]; /* Make sure these macros specify a sufficient size */ unsigned char history[USCXML_MAX_NR_STATES_BYTES]; unsigned char invocations[USCXML_MAX_NR_STATES_BYTES]; unsigned char initialized_data[USCXML_MAX_NR_STATES_BYTES]; void* user_data; void* event; dequeue_internal_t dequeue_internal; dequeue_external_t dequeue_external; is_matched_t is_matched; is_true_t is_true; raise_done_event_t raise_done_event; exec_content_log_t exec_content_log; exec_content_raise_t exec_content_raise; exec_content_send_t exec_content_send; exec_content_foreach_init_t exec_content_foreach_init; exec_content_foreach_next_t exec_content_foreach_next; exec_content_foreach_done_t exec_content_foreach_done; exec_content_assign_t exec_content_assign; exec_content_init_t exec_content_init; exec_content_cancel_t exec_content_cancel; exec_content_script_t exec_content_script; invoke_t invoke; }; #define USCXML_NO_GEN_C_TYPES #endif /* forward declare machines to allow references */ extern const uscxml_machine _uscxml_ED395C23__machine; extern const uscxml_machine _uscxml_7847B274__machine; extern const uscxml_machine _uscxml_DB2A83B0__machine; #ifndef USCXML_NO_ELEM_INFO static const uscxml_elem_data _uscxml_ED395C23__elem_datas[2] = { /* id, src, expr, content */ { "Var1", NULL, "1", NULL }, { NULL, NULL, NULL, NULL } }; static const uscxml_elem_param _uscxml_ED395C23__elem_params[2] = { /* name, expr, location */ { "Var1", "1", NULL }, { NULL, NULL, NULL } }; static const uscxml_elem_send _uscxml_ED395C23__elem_sends[1] = { { /* event */ "timeout", /* eventexpr */ NULL, /* target */ NULL, /* targetexpr */ NULL, /* type */ NULL, /* typeexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* delay */ 2000, /* delayexpr */ NULL, /* namelist */ NULL, /* content */ NULL, /* contentexpr */ NULL, /* params */ NULL } }; static const uscxml_elem_donedata _uscxml_ED395C23__elem_donedatas[1] = { /* source, content, contentexpr, params */ { 0, NULL, NULL, NULL } }; #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_elem_invoke _uscxml_ED395C23__elem_invokes[2] = { { /* machine */ &_uscxml_7847B274__machine, /* type */ "http://www.w3.org/TR/scxml/", /* typeexpr */ NULL, /* src */ NULL, /* srcexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* sourcename */ "s01", /* namelist */ "Var1", /* autoforward */ 0, /* params */ NULL, /* finalize */ NULL, /* content */ NULL, /* contentexpr */ NULL, }, { /* machine */ &_uscxml_DB2A83B0__machine, /* type */ "http://www.w3.org/TR/scxml/", /* typeexpr */ NULL, /* src */ NULL, /* srcexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* sourcename */ "s02", /* namelist */ NULL, /* autoforward */ 0, /* params */ &_uscxml_ED395C23__elem_params[0], /* finalize */ NULL, /* content */ NULL, /* contentexpr */ NULL, } }; #endif #ifndef USCXML_NO_EXEC_CONTENT static int _uscxml_ED395C23__s0_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_send != NULL) { if ((ctx->exec_content_send(ctx, &_uscxml_ED395C23__elem_sends[0])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } static int _uscxml_ED395C23__s0_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { _uscxml_ED395C23__s0_on_entry_0(ctx, state, event); return USCXML_ERR_OK; } static int _uscxml_ED395C23__s01_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) { ctx->invoke(ctx, s, &_uscxml_ED395C23__elem_invokes[0], uninvoke); return USCXML_ERR_OK; } static int _uscxml_ED395C23__s02_invoke(const uscxml_ctx* ctx, const uscxml_state* s, const uscxml_elem_invoke* invocation, unsigned char uninvoke) { ctx->invoke(ctx, s, &_uscxml_ED395C23__elem_invokes[1], uninvoke); return USCXML_ERR_OK; } static int _uscxml_ED395C23__pass_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_log != NULL) { if unlikely((ctx->exec_content_log(ctx, "Outcome", "'pass'")) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } static int _uscxml_ED395C23__pass_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { _uscxml_ED395C23__pass_on_entry_0(ctx, state, event); return USCXML_ERR_OK; } static int _uscxml_ED395C23__fail_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_log != NULL) { if unlikely((ctx->exec_content_log(ctx, "Outcome", "'fail'")) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } static int _uscxml_ED395C23__fail_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { _uscxml_ED395C23__fail_on_entry_0(ctx, state, event); return USCXML_ERR_OK; } #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_state _uscxml_ED395C23__states[6] = { { /* state number 0 */ /* name */ NULL, /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x32 /* 010011 */ }, /* completion */ { 0x02 /* 010000 */ }, /* ancestors */ { 0x00 /* 000000 */ }, /* data */ &_uscxml_ED395C23__elem_datas[0], /* type */ USCXML_STATE_COMPOUND, }, { /* state number 1 */ /* name */ "s0", /* parent */ 0, /* onentry */ _uscxml_ED395C23__s0_on_entry, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x0c /* 001100 */ }, /* completion */ { 0x04 /* 001000 */ }, /* ancestors */ { 0x01 /* 100000 */ }, /* data */ NULL, /* type */ USCXML_STATE_COMPOUND, }, { /* state number 2 */ /* name */ "s01", /* parent */ 1, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ _uscxml_ED395C23__s01_invoke, /* children */ { 0x00 /* 000000 */ }, /* completion */ { 0x00 /* 000000 */ }, /* ancestors */ { 0x03 /* 110000 */ }, /* data */ NULL, /* type */ USCXML_STATE_ATOMIC, }, { /* state number 3 */ /* name */ "s02", /* parent */ 1, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ _uscxml_ED395C23__s02_invoke, /* children */ { 0x00 /* 000000 */ }, /* completion */ { 0x00 /* 000000 */ }, /* ancestors */ { 0x03 /* 110000 */ }, /* data */ NULL, /* type */ USCXML_STATE_ATOMIC, }, { /* state number 4 */ /* name */ "pass", /* parent */ 0, /* onentry */ _uscxml_ED395C23__pass_on_entry, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x00 /* 000000 */ }, /* completion */ { 0x00 /* 000000 */ }, /* ancestors */ { 0x01 /* 100000 */ }, /* data */ NULL, /* type */ USCXML_STATE_FINAL, }, { /* state number 5 */ /* name */ "fail", /* parent */ 0, /* onentry */ _uscxml_ED395C23__fail_on_entry, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x00 /* 000000 */ }, /* completion */ { 0x00 /* 000000 */ }, /* ancestors */ { 0x01 /* 100000 */ }, /* data */ NULL, /* type */ USCXML_STATE_FINAL, } }; #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_transition _uscxml_ED395C23__transitions[5] = { { /* transition number 1 with priority 0 target: s02 */ /* source */ 2, /* target */ { 0x08 /* 000100 */ }, /* event */ "success", /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ NULL, /* type */ 0, /* conflicts */ { 0x1f /* 11111 */ }, /* exit set */ { 0x0c /* 001100 */ } }, { /* transition number 2 with priority 1 target: fail */ /* source */ 2, /* target */ { 0x20 /* 000001 */ }, /* event */ "failure", /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ NULL, /* type */ 0, /* conflicts */ { 0x1f /* 11111 */ }, /* exit set */ { 0x3e /* 011111 */ } }, { /* transition number 3 with priority 2 target: pass */ /* source */ 3, /* target */ { 0x10 /* 000010 */ }, /* event */ "success", /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ NULL, /* type */ 0, /* conflicts */ { 0x1f /* 11111 */ }, /* exit set */ { 0x3e /* 011111 */ } }, { /* transition number 4 with priority 3 target: fail */ /* source */ 3, /* target */ { 0x20 /* 000001 */ }, /* event */ "failure", /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ NULL, /* type */ 0, /* conflicts */ { 0x1f /* 11111 */ }, /* exit set */ { 0x3e /* 011111 */ } }, { /* transition number 0 with priority 4 target: fail */ /* source */ 1, /* target */ { 0x20 /* 000001 */ }, /* event */ "timeout", /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ NULL, /* type */ 0, /* conflicts */ { 0x1f /* 11111 */ }, /* exit set */ { 0x3e /* 011111 */ } } }; #endif #ifndef USCXML_NO_ELEM_INFO #ifndef USCXML_MACHINE # define USCXML_MACHINE _uscxml_ED395C23__machine #endif #define USCXML_MACHINE_0 _uscxml_ED395C23__machine #define USCXML_MACHINE_TEST240_SCXML _uscxml_ED395C23__machine const uscxml_machine _uscxml_ED395C23__machine = { /* flags */ 0, /* nr_states */ 6, /* nr_transitions */ 5, /* name */ "test240.scxml", /* datamodel */ "lua", /* uuid */ "ED395C2320352170727CA99C3797822B", /* states */ &_uscxml_ED395C23__states[0], /* transitions */ &_uscxml_ED395C23__transitions[0], /* parent */ NULL, /* donedata */ &_uscxml_ED395C23__elem_donedatas[0], /* script */ NULL }; #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_elem_data _uscxml_7847B274__elem_datas[2] = { /* id, src, expr, content */ { "Var1", NULL, "0", NULL }, { NULL, NULL, NULL, NULL } }; static const uscxml_elem_send _uscxml_7847B274__elem_sends[2] = { { /* event */ "success", /* eventexpr */ NULL, /* target */ "#_parent", /* targetexpr */ NULL, /* type */ NULL, /* typeexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* delay */ 0, /* delayexpr */ NULL, /* namelist */ NULL, /* content */ NULL, /* contentexpr */ NULL, /* params */ NULL }, { /* event */ "failure", /* eventexpr */ NULL, /* target */ "#_parent", /* targetexpr */ NULL, /* type */ NULL, /* typeexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* delay */ 0, /* delayexpr */ NULL, /* namelist */ NULL, /* content */ NULL, /* contentexpr */ NULL, /* params */ NULL } }; static const uscxml_elem_donedata _uscxml_7847B274__elem_donedatas[1] = { /* source, content, contentexpr, params */ { 0, NULL, NULL, NULL } }; #endif #ifndef USCXML_NO_ELEM_INFO #endif #ifndef USCXML_NO_EXEC_CONTENT static int _uscxml_7847B274__sub01_transition0_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) { if likely(ctx->is_true != NULL) { return (ctx->is_true(ctx, "Var1==1")); } return USCXML_ERR_MISSING_CALLBACK; } static int _uscxml_7847B274__sub01_transition0_on_trans(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_send != NULL) { if ((ctx->exec_content_send(ctx, &_uscxml_7847B274__elem_sends[0])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } static int _uscxml_7847B274__sub01_transition1_on_trans(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_send != NULL) { if ((ctx->exec_content_send(ctx, &_uscxml_7847B274__elem_sends[1])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_state _uscxml_7847B274__states[3] = { { /* state number 0 */ /* name */ NULL, /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x06 /* 011 */ }, /* completion */ { 0x02 /* 010 */ }, /* ancestors */ { 0x00 /* 000 */ }, /* data */ &_uscxml_7847B274__elem_datas[0], /* type */ USCXML_STATE_COMPOUND, }, { /* state number 1 */ /* name */ "sub01", /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x00 /* 000 */ }, /* completion */ { 0x00 /* 000 */ }, /* ancestors */ { 0x01 /* 100 */ }, /* data */ NULL, /* type */ USCXML_STATE_ATOMIC, }, { /* state number 2 */ /* name */ "subFinal1", /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x00 /* 000 */ }, /* completion */ { 0x00 /* 000 */ }, /* ancestors */ { 0x01 /* 100 */ }, /* data */ NULL, /* type */ USCXML_STATE_FINAL, } }; #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_transition _uscxml_7847B274__transitions[2] = { { /* transition number 0 with priority 0 target: subFinal1 */ /* source */ 1, /* target */ { 0x04 /* 001 */ }, /* event */ NULL, /* condition */ "Var1==1", /* is_enabled */ _uscxml_7847B274__sub01_transition0_is_enabled, /* ontrans */ _uscxml_7847B274__sub01_transition0_on_trans, /* type */ USCXML_TRANS_SPONTANEOUS, /* conflicts */ { 0x03 /* 11 */ }, /* exit set */ { 0x06 /* 011 */ } }, { /* transition number 1 with priority 1 target: subFinal1 */ /* source */ 1, /* target */ { 0x04 /* 001 */ }, /* event */ NULL, /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ _uscxml_7847B274__sub01_transition1_on_trans, /* type */ USCXML_TRANS_SPONTANEOUS, /* conflicts */ { 0x03 /* 11 */ }, /* exit set */ { 0x06 /* 011 */ } } }; #endif #ifndef USCXML_NO_ELEM_INFO #ifndef USCXML_MACHINE # define USCXML_MACHINE _uscxml_7847B274__machine #endif #define USCXML_MACHINE_1 _uscxml_7847B274__machine #define USCXML_MACHINE_TEST240_SCXML_S01_INVOKE0_CONTENT0_SCXML0 _uscxml_7847B274__machine const uscxml_machine _uscxml_7847B274__machine = { /* flags */ 0, /* nr_states */ 3, /* nr_transitions */ 2, /* name */ "test240.scxml.s01_invoke0_content0_scxml0", /* datamodel */ "lua", /* uuid */ "7847B274CA8610349BFA9F21A78B590E", /* states */ &_uscxml_7847B274__states[0], /* transitions */ &_uscxml_7847B274__transitions[0], /* parent */ &_uscxml_ED395C23__machine, /* donedata */ &_uscxml_7847B274__elem_donedatas[0], /* script */ NULL }; #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_elem_data _uscxml_DB2A83B0__elem_datas[2] = { /* id, src, expr, content */ { "Var1", NULL, "0", NULL }, { NULL, NULL, NULL, NULL } }; static const uscxml_elem_send _uscxml_DB2A83B0__elem_sends[2] = { { /* event */ "success", /* eventexpr */ NULL, /* target */ "#_parent", /* targetexpr */ NULL, /* type */ NULL, /* typeexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* delay */ 0, /* delayexpr */ NULL, /* namelist */ NULL, /* content */ NULL, /* contentexpr */ NULL, /* params */ NULL }, { /* event */ "failure", /* eventexpr */ NULL, /* target */ "#_parent", /* targetexpr */ NULL, /* type */ NULL, /* typeexpr */ NULL, /* id */ NULL, /* idlocation */ NULL, /* delay */ 0, /* delayexpr */ NULL, /* namelist */ NULL, /* content */ NULL, /* contentexpr */ NULL, /* params */ NULL } }; static const uscxml_elem_donedata _uscxml_DB2A83B0__elem_donedatas[1] = { /* source, content, contentexpr, params */ { 0, NULL, NULL, NULL } }; #endif #ifndef USCXML_NO_ELEM_INFO #endif #ifndef USCXML_NO_EXEC_CONTENT static int _uscxml_DB2A83B0__sub02_transition0_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) { if likely(ctx->is_true != NULL) { return (ctx->is_true(ctx, "Var1==1")); } return USCXML_ERR_MISSING_CALLBACK; } static int _uscxml_DB2A83B0__sub02_transition0_on_trans(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_send != NULL) { if ((ctx->exec_content_send(ctx, &_uscxml_DB2A83B0__elem_sends[0])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } static int _uscxml_DB2A83B0__sub02_transition1_on_trans(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_send != NULL) { if ((ctx->exec_content_send(ctx, &_uscxml_DB2A83B0__elem_sends[1])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } return USCXML_ERR_OK; } #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_state _uscxml_DB2A83B0__states[3] = { { /* state number 0 */ /* name */ NULL, /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x06 /* 011 */ }, /* completion */ { 0x02 /* 010 */ }, /* ancestors */ { 0x00 /* 000 */ }, /* data */ &_uscxml_DB2A83B0__elem_datas[0], /* type */ USCXML_STATE_COMPOUND, }, { /* state number 1 */ /* name */ "sub02", /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x00 /* 000 */ }, /* completion */ { 0x00 /* 000 */ }, /* ancestors */ { 0x01 /* 100 */ }, /* data */ NULL, /* type */ USCXML_STATE_ATOMIC, }, { /* state number 2 */ /* name */ "subFinal2", /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, /* children */ { 0x00 /* 000 */ }, /* completion */ { 0x00 /* 000 */ }, /* ancestors */ { 0x01 /* 100 */ }, /* data */ NULL, /* type */ USCXML_STATE_FINAL, } }; #endif #ifndef USCXML_NO_ELEM_INFO static const uscxml_transition _uscxml_DB2A83B0__transitions[2] = { { /* transition number 0 with priority 0 target: subFinal2 */ /* source */ 1, /* target */ { 0x04 /* 001 */ }, /* event */ NULL, /* condition */ "Var1==1", /* is_enabled */ _uscxml_DB2A83B0__sub02_transition0_is_enabled, /* ontrans */ _uscxml_DB2A83B0__sub02_transition0_on_trans, /* type */ USCXML_TRANS_SPONTANEOUS, /* conflicts */ { 0x03 /* 11 */ }, /* exit set */ { 0x06 /* 011 */ } }, { /* transition number 1 with priority 1 target: subFinal2 */ /* source */ 1, /* target */ { 0x04 /* 001 */ }, /* event */ NULL, /* condition */ NULL, /* is_enabled */ NULL, /* ontrans */ _uscxml_DB2A83B0__sub02_transition1_on_trans, /* type */ USCXML_TRANS_SPONTANEOUS, /* conflicts */ { 0x03 /* 11 */ }, /* exit set */ { 0x06 /* 011 */ } } }; #endif #ifndef USCXML_NO_ELEM_INFO #ifndef USCXML_MACHINE # define USCXML_MACHINE _uscxml_DB2A83B0__machine #endif #define USCXML_MACHINE_2 _uscxml_DB2A83B0__machine #define USCXML_MACHINE_TEST240_SCXML_S02_INVOKE0_CONTENT0_SCXML0 _uscxml_DB2A83B0__machine const uscxml_machine _uscxml_DB2A83B0__machine = { /* flags */ 0, /* nr_states */ 3, /* nr_transitions */ 2, /* name */ "test240.scxml.s02_invoke0_content0_scxml0", /* datamodel */ "lua", /* uuid */ "DB2A83B067CD692F49AB0A6A6F13C5D0", /* states */ &_uscxml_DB2A83B0__states[0], /* transitions */ &_uscxml_DB2A83B0__transitions[0], /* parent */ &_uscxml_ED395C23__machine, /* donedata */ &_uscxml_DB2A83B0__elem_donedatas[0], /* script */ NULL }; #endif #ifdef USCXML_VERBOSE /** * Print name of states contained in a (debugging). */ static void printStateNames(const uscxml_ctx* ctx, const unsigned char* a, size_t length) { size_t i; const char* seperator = ""; for (i = 0; i < length; i++) { if (BIT_HAS(i, a)) { printf("%s%s", seperator, (USCXML_GET_STATE(i).name != NULL ? USCXML_GET_STATE(i).name : "UNK")); seperator = ", "; } } printf("\n"); } /** * Print bits set in a in a binary representation (debugging). */ static void printBitsetIndices(const unsigned char* a, size_t length) { size_t i; const char* seperator = ""; for (i = 0; i < length; i++) { if (BIT_HAS(i, a)) { printf("%s%zu", seperator, i); seperator = ", "; } } printf("\n"); } #endif #ifndef USCXML_NO_BIT_OPERATIONS /** * Return true if there is a common bit in a and b. */ static int bit_has_and(const unsigned char* a, const unsigned char* b, size_t i) { while(i--) { if (a[i] & b[i]) return 1; } return 0; } /** * Set all bits to 0, this corresponds to memset(a, 0, i), * but does not require string.h or cstring. */ static void bit_clear_all(unsigned char* a, size_t i) { while(i--) { a[i] = 0; } } /** * Return true if there is any bit set in a. */ static int bit_has_any(unsigned const char* a, size_t i) { while(i--) { if (a[i] > 0) return 1; } return 0; } /** * Set all bits from given mask in dest, this is |= for bit arrays. */ static void bit_or(unsigned char* dest, const unsigned char* mask, size_t i) { while(i--) { dest[i] |= mask[i]; } } /** * Copy all bits from source to dest, this corresponds to memcpy(a, b, i), * but does not require string.h or cstring. */ static void bit_copy(unsigned char* dest, const unsigned char* source, size_t i) { while(i--) { dest[i] = source[i]; } } /** * Unset bits from mask in dest. */ static void bit_and_not(unsigned char* dest, const unsigned char* mask, size_t i) { while(i--) { dest[i] &= ~mask[i]; } } /** * Set bits from mask in dest. */ static void bit_and(unsigned char* dest, const unsigned char* mask, size_t i) { while(i--) { dest[i] &= mask[i]; }; } #define USCXML_NO_BIT_OPERATIONS #endif #ifndef USCXML_NO_STEP_FUNCTION int uscxml_step(uscxml_ctx* ctx) { USCXML_NR_STATES_TYPE i, j, k; USCXML_NR_STATES_TYPE nr_states_bytes = ((USCXML_NUMBER_STATES + 7) & ~7) >> 3; USCXML_NR_TRANS_TYPE nr_trans_bytes = ((USCXML_NUMBER_TRANS + 7) & ~7) >> 3; int err = USCXML_ERR_OK; unsigned char conflicts [USCXML_MAX_NR_TRANS_BYTES]; unsigned char trans_set [USCXML_MAX_NR_TRANS_BYTES]; unsigned char target_set [USCXML_MAX_NR_STATES_BYTES]; unsigned char exit_set [USCXML_MAX_NR_STATES_BYTES]; unsigned char entry_set [USCXML_MAX_NR_STATES_BYTES]; unsigned char tmp_states [USCXML_MAX_NR_STATES_BYTES]; #ifdef USCXML_VERBOSE printf("Config: "); printStateNames(ctx, ctx->config, USCXML_NUMBER_STATES); #endif if (ctx->flags & USCXML_CTX_FINISHED) return USCXML_ERR_DONE; if (ctx->flags & USCXML_CTX_TOP_LEVEL_FINAL) { /* exit all remaining states */ i = USCXML_NUMBER_STATES; while(i-- > 0) { if (BIT_HAS(i, ctx->config)) { /* call all on exit handlers */ if (USCXML_GET_STATE(i).on_exit != NULL) { if unlikely((err = USCXML_GET_STATE(i).on_exit(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK) return err; } } if (BIT_HAS(i, ctx->invocations)) { if (USCXML_GET_STATE(i).invoke != NULL) USCXML_GET_STATE(i).invoke(ctx, &USCXML_GET_STATE(i), NULL, 1); BIT_CLEAR(i, ctx->invocations); } } ctx->flags |= USCXML_CTX_FINISHED; return USCXML_ERR_DONE; } bit_clear_all(target_set, nr_states_bytes); bit_clear_all(trans_set, nr_trans_bytes); if unlikely(ctx->flags == USCXML_CTX_PRISTINE) { if (ctx->machine->script != NULL) ctx->machine->script(ctx, &ctx->machine->states[0], NULL); bit_or(target_set, ctx->machine->states[0].completion, nr_states_bytes); ctx->flags |= USCXML_CTX_SPONTANEOUS | USCXML_CTX_INITIALIZED; goto ESTABLISH_ENTRY_SET; } DEQUEUE_EVENT: if (ctx->flags & USCXML_CTX_SPONTANEOUS) { ctx->event = NULL; goto SELECT_TRANSITIONS; } if (ctx->dequeue_internal != NULL && (ctx->event = ctx->dequeue_internal(ctx)) != NULL) { goto SELECT_TRANSITIONS; } /* manage invocations */ for (i = 0; i < USCXML_NUMBER_STATES; i++) { /* uninvoke */ if (!BIT_HAS(i, ctx->config) && BIT_HAS(i, ctx->invocations)) { if (USCXML_GET_STATE(i).invoke != NULL) USCXML_GET_STATE(i).invoke(ctx, &USCXML_GET_STATE(i), NULL, 1); BIT_CLEAR(i, ctx->invocations) } /* invoke */ if (BIT_HAS(i, ctx->config) && !BIT_HAS(i, ctx->invocations)) { if (USCXML_GET_STATE(i).invoke != NULL) USCXML_GET_STATE(i).invoke(ctx, &USCXML_GET_STATE(i), NULL, 0); BIT_SET_AT(i, ctx->invocations) } } if (ctx->dequeue_external != NULL && (ctx->event = ctx->dequeue_external(ctx)) != NULL) { goto SELECT_TRANSITIONS; } if (ctx->dequeue_external == NULL) { return USCXML_ERR_DONE; } return USCXML_ERR_IDLE; SELECT_TRANSITIONS: bit_clear_all(conflicts, nr_trans_bytes); bit_clear_all(exit_set, nr_states_bytes); for (i = 0; i < USCXML_NUMBER_TRANS; i++) { /* never select history or initial transitions automatically */ if unlikely(USCXML_GET_TRANS(i).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) continue; /* is the transition active? */ if (BIT_HAS(USCXML_GET_TRANS(i).source, ctx->config)) { /* is it non-conflicting? */ if (!BIT_HAS(i, conflicts)) { /* is it spontaneous with an event or vice versa? */ if ((USCXML_GET_TRANS(i).event == NULL && ctx->event == NULL) || (USCXML_GET_TRANS(i).event != NULL && ctx->event != NULL)) { /* is it enabled? */ if ((ctx->event == NULL || ctx->is_matched(ctx, &USCXML_GET_TRANS(i), ctx->event) > 0) && (USCXML_GET_TRANS(i).condition == NULL || USCXML_GET_TRANS(i).is_enabled(ctx, &USCXML_GET_TRANS(i)) > 0)) { /* remember that we found a transition */ ctx->flags |= USCXML_CTX_TRANSITION_FOUND; /* transitions that are pre-empted */ bit_or(conflicts, USCXML_GET_TRANS(i).conflicts, nr_trans_bytes); /* states that are directly targeted (resolve as entry-set later) */ bit_or(target_set, USCXML_GET_TRANS(i).target, nr_states_bytes); /* states that will be left */ bit_or(exit_set, USCXML_GET_TRANS(i).exit_set, nr_states_bytes); BIT_SET_AT(i, trans_set); } } } } } bit_and(exit_set, ctx->config, nr_states_bytes); if (ctx->flags & USCXML_CTX_TRANSITION_FOUND) { ctx->flags |= USCXML_CTX_SPONTANEOUS; ctx->flags &= ~USCXML_CTX_TRANSITION_FOUND; } else { ctx->flags &= ~USCXML_CTX_SPONTANEOUS; goto DEQUEUE_EVENT; } #ifdef USCXML_VERBOSE printf("Targets: "); printStateNames(ctx, target_set, USCXML_NUMBER_STATES); #endif #ifdef USCXML_VERBOSE printf("Exiting: "); printStateNames(ctx, exit_set, USCXML_NUMBER_STATES); #endif #ifdef USCXML_VERBOSE printf("History: "); printStateNames(ctx, ctx->history, USCXML_NUMBER_STATES); #endif /* REMEMBER_HISTORY: */ for (i = 0; i < USCXML_NUMBER_STATES; i++) { if unlikely(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_SHALLOW || USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_DEEP) { /* a history state whose parent is about to be exited */ if unlikely(BIT_HAS(USCXML_GET_STATE(i).parent, exit_set)) { bit_copy(tmp_states, USCXML_GET_STATE(i).completion, nr_states_bytes); /* set those states who were enabled */ bit_and(tmp_states, ctx->config, nr_states_bytes); /* clear current history with completion mask */ bit_and_not(ctx->history, USCXML_GET_STATE(i).completion, nr_states_bytes); /* set history */ bit_or(ctx->history, tmp_states, nr_states_bytes); } } } ESTABLISH_ENTRY_SET: /* calculate new entry set */ bit_copy(entry_set, target_set, nr_states_bytes); /* iterate for ancestors */ for (i = 0; i < USCXML_NUMBER_STATES; i++) { if (BIT_HAS(i, entry_set)) { bit_or(entry_set, USCXML_GET_STATE(i).ancestors, nr_states_bytes); } } /* iterate for descendants */ for (i = 0; i < USCXML_NUMBER_STATES; i++) { if (BIT_HAS(i, entry_set)) { switch (USCXML_STATE_MASK(USCXML_GET_STATE(i).type)) { case USCXML_STATE_PARALLEL: { bit_or(entry_set, USCXML_GET_STATE(i).completion, nr_states_bytes); break; } #ifndef USCXML_NO_HISTORY case USCXML_STATE_HISTORY_SHALLOW: case USCXML_STATE_HISTORY_DEEP: { if (!bit_has_and(USCXML_GET_STATE(i).completion, ctx->history, nr_states_bytes) && !BIT_HAS(USCXML_GET_STATE(i).parent, ctx->config)) { /* nothing set for history, look for a default transition */ for (j = 0; j < USCXML_NUMBER_TRANS; j++) { if unlikely(ctx->machine->transitions[j].source == i) { bit_or(entry_set, ctx->machine->transitions[j].target, nr_states_bytes); if(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_DEEP && !bit_has_and(ctx->machine->transitions[j].target, USCXML_GET_STATE(i).children, nr_states_bytes)) { for (k = i + 1; k < USCXML_NUMBER_STATES; k++) { if (BIT_HAS(k, ctx->machine->transitions[j].target)) { bit_or(entry_set, ctx->machine->states[k].ancestors, nr_states_bytes); break; } } } BIT_SET_AT(j, trans_set); break; } /* Note: SCXML mandates every history to have a transition! */ } } else { bit_copy(tmp_states, USCXML_GET_STATE(i).completion, nr_states_bytes); bit_and(tmp_states, ctx->history, nr_states_bytes); bit_or(entry_set, tmp_states, nr_states_bytes); if (USCXML_GET_STATE(i).type == (USCXML_STATE_HAS_HISTORY | USCXML_STATE_HISTORY_DEEP)) { /* a deep history state with nested histories -> more completion */ for (j = i + 1; j < USCXML_NUMBER_STATES; j++) { if (BIT_HAS(j, USCXML_GET_STATE(i).completion) && BIT_HAS(j, entry_set) && (ctx->machine->states[j].type & USCXML_STATE_HAS_HISTORY)) { for (k = j + 1; k < USCXML_NUMBER_STATES; k++) { /* add nested history to entry_set */ if ((USCXML_STATE_MASK(ctx->machine->states[k].type) == USCXML_STATE_HISTORY_DEEP || USCXML_STATE_MASK(ctx->machine->states[k].type) == USCXML_STATE_HISTORY_SHALLOW) && BIT_HAS(k, ctx->machine->states[j].children)) { /* a nested history state */ BIT_SET_AT(k, entry_set); } } } } } } break; } #endif case USCXML_STATE_INITIAL: { for (j = 0; j < USCXML_NUMBER_TRANS; j++) { if (ctx->machine->transitions[j].source == i) { BIT_SET_AT(j, trans_set); BIT_CLEAR(i, entry_set); bit_or(entry_set, ctx->machine->transitions[j].target, nr_states_bytes); for (k = i + 1; k < USCXML_NUMBER_STATES; k++) { if (BIT_HAS(k, ctx->machine->transitions[j].target)) { bit_or(entry_set, ctx->machine->states[k].ancestors, nr_states_bytes); } } } } break; } case USCXML_STATE_COMPOUND: { /* we need to check whether one child is already in entry_set */ if (!bit_has_and(entry_set, USCXML_GET_STATE(i).children, nr_states_bytes) && (!bit_has_and(ctx->config, USCXML_GET_STATE(i).children, nr_states_bytes) || bit_has_and(exit_set, USCXML_GET_STATE(i).children, nr_states_bytes))) { bit_or(entry_set, USCXML_GET_STATE(i).completion, nr_states_bytes); if (!bit_has_and(USCXML_GET_STATE(i).completion, USCXML_GET_STATE(i).children, nr_states_bytes)) { /* deep completion */ for (j = i + 1; j < USCXML_NUMBER_STATES; j++) { if (BIT_HAS(j, USCXML_GET_STATE(i).completion)) { bit_or(entry_set, ctx->machine->states[j].ancestors, nr_states_bytes); break; /* completion of compound is single state */ } } } } break; } } } } #ifdef USCXML_VERBOSE printf("Transitions: "); printBitsetIndices(trans_set, sizeof(char) * 8 * nr_trans_bytes); #endif /* EXIT_STATES: */ i = USCXML_NUMBER_STATES; while(i-- > 0) { if (BIT_HAS(i, exit_set) && BIT_HAS(i, ctx->config)) { /* call all on exit handlers */ if (USCXML_GET_STATE(i).on_exit != NULL) { if unlikely((err = USCXML_GET_STATE(i).on_exit(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK) return err; } BIT_CLEAR(i, ctx->config); } } /* TAKE_TRANSITIONS: */ for (i = 0; i < USCXML_NUMBER_TRANS; i++) { if (BIT_HAS(i, trans_set) && (USCXML_GET_TRANS(i).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) == 0) { /* call executable content in transition */ if (USCXML_GET_TRANS(i).on_transition != NULL) { if unlikely((err = USCXML_GET_TRANS(i).on_transition(ctx, &ctx->machine->states[USCXML_GET_TRANS(i).source], ctx->event)) != USCXML_ERR_OK) return err; } } } #ifdef USCXML_VERBOSE printf("Entering: "); printStateNames(ctx, entry_set, USCXML_NUMBER_STATES); #endif /* ENTER_STATES: */ for (i = 0; i < USCXML_NUMBER_STATES; i++) { if (BIT_HAS(i, entry_set) && !BIT_HAS(i, ctx->config)) { /* these are no proper states */ if unlikely(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_DEEP || USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_HISTORY_SHALLOW || USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_INITIAL) continue; BIT_SET_AT(i, ctx->config); /* initialize data */ if (!BIT_HAS(i, ctx->initialized_data)) { if unlikely(USCXML_GET_STATE(i).data != NULL && ctx->exec_content_init != NULL) { ctx->exec_content_init(ctx, USCXML_GET_STATE(i).data); } BIT_SET_AT(i, ctx->initialized_data); } if (USCXML_GET_STATE(i).on_entry != NULL) { if unlikely((err = USCXML_GET_STATE(i).on_entry(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK) return err; } /* take history and initial transitions */ for (j = 0; j < USCXML_NUMBER_TRANS; j++) { if unlikely(BIT_HAS(j, trans_set) && (ctx->machine->transitions[j].type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) && ctx->machine->states[ctx->machine->transitions[j].source].parent == i) { /* call executable content in transition */ if (ctx->machine->transitions[j].on_transition != NULL) { if unlikely((err = ctx->machine->transitions[j].on_transition(ctx, &USCXML_GET_STATE(i), ctx->event)) != USCXML_ERR_OK) return err; } } } /* handle final states */ if unlikely(USCXML_STATE_MASK(USCXML_GET_STATE(i).type) == USCXML_STATE_FINAL) { if unlikely(USCXML_GET_STATE(i).ancestors[0] == 0x01) { ctx->flags |= USCXML_CTX_TOP_LEVEL_FINAL; } else { /* raise done event */ const uscxml_elem_donedata* donedata = &ctx->machine->donedata[0]; while(USCXML_ELEM_DONEDATA_IS_SET(donedata)) { if unlikely(donedata->source == i) break; donedata++; } ctx->raise_done_event(ctx, &ctx->machine->states[USCXML_GET_STATE(i).parent], (USCXML_ELEM_DONEDATA_IS_SET(donedata) ? donedata : NULL)); } /** * are we the last final state to leave a parallel state?: * 1. Gather all parallel states in our ancestor chain * 2. Find all states for which these parallels are ancestors * 3. Iterate all active final states and remove their ancestors * 4. If a state remains, not all children of a parallel are final */ for (j = 0; j < USCXML_NUMBER_STATES; j++) { if unlikely(USCXML_STATE_MASK(ctx->machine->states[j].type) == USCXML_STATE_PARALLEL && BIT_HAS(j, USCXML_GET_STATE(i).ancestors)) { bit_clear_all(tmp_states, nr_states_bytes); for (k = 0; k < USCXML_NUMBER_STATES; k++) { if unlikely(BIT_HAS(j, ctx->machine->states[k].ancestors) && BIT_HAS(k, ctx->config)) { if (USCXML_STATE_MASK(ctx->machine->states[k].type) == USCXML_STATE_FINAL) { bit_and_not(tmp_states, ctx->machine->states[k].ancestors, nr_states_bytes); } else { BIT_SET_AT(k, tmp_states); } } } if unlikely(!bit_has_any(tmp_states, nr_states_bytes)) { ctx->raise_done_event(ctx, &ctx->machine->states[j], NULL); } } } } } } return USCXML_ERR_OK; } #define USCXML_NO_STEP_FUNCTION #endif
the_stack_data/18629.c
/*- * Copyright (c) 2013 David Chisnall * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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. * * $FreeBSD: head/lib/msun/src/imprecise.c 255294 2013-09-06 07:58:23Z theraven $ */ #include <float.h> #include <math.h> /* * If long double is not the same size as double, then these will lose * precision and we should emit a warning whenever something links against * them. */ #if (LDBL_MANT_DIG > 53) #define WARN_IMPRECISE(x) \ __warn_references(x, # x " has lower than advertised precision"); #else #define WARN_IMPRECISE(x) #endif /* * Declare the functions as weak variants so that other libraries providing * real versions can override them. */ #define DECLARE_WEAK(x)\ __weak_reference(imprecise_## x, x);\ WARN_IMPRECISE(x) #define DECLARE_FORMER_IMPRECISE(f) \ __asm__(".symver imprecise_" #f "l," #f "[email protected]"); \ long double imprecise_ ## f ## l(long double v) { return f(v); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-prototypes" __asm__(".symver imprecise_powl,[email protected]"); long double imprecise_powl(long double x, long double y) { return pow(x, y); } DECLARE_FORMER_IMPRECISE(cosh); DECLARE_FORMER_IMPRECISE(erfc); DECLARE_FORMER_IMPRECISE(erf); DECLARE_FORMER_IMPRECISE(sinh); DECLARE_FORMER_IMPRECISE(tanh); DECLARE_FORMER_IMPRECISE(tgamma); DECLARE_FORMER_IMPRECISE(lgamma); #pragma GCC diagnostic pop
the_stack_data/14200147.c
// Copyright (c) 2015 RV-Match Team. All Rights Reserved. int main() { int x = 0; int *y = 1 ? &x : 0; return 0; }
the_stack_data/28263293.c
#include <stdlib.h> #include <stdio.h> typedef struct NoTag{ int info; struct NoTag *next; struct NoTag *prev; }no; void main(){ no *L; int sel,x; iniLista(&L); while (sel != 0){ printf("\n\n1: Inserir Final da Lista\n2: Inserir Inicio da Lista\n3: Exibir a Lista\n4: Remover Final da Lista\n5: Remover Inicio da Lista\n6: Exibir o Maior Numero\n7: Remover Item\n0: Sair\n ---> "); scanf("%d",&sel); switch (sel) { case 1: printf("Digite o numero a ser inserido: ");scanf("%d",&x);inserefinalLista(&L,x);break; case 2: printf("Digite o numero a ser inserido: ");scanf("%d",&x);insereinicioLista(&L,x);break; case 3: exibeLista(L); break; case 4: removefinalLista(&L); break; case 5: removeinicioLista(&L); break; case 6: printf("%d\n",maiornum(L)); break; case 7: scanf("%d",&x); removeitem(&L,x);break; case 8: scanf("%d",&x); inserirordem(&L,x); break; } } } iniLista(no **L){ *L = NULL; } insereinicioLista(no **L,int x){ no *N; N = (no *) malloc(sizeof (no)); N->info = x; N->prev = NULL; N->next = *L; if (*L != NULL){ (*L)->prev = N; } *L = N; } inserefinalLista(no **L,int x){ no *P,*N; N = (no *) malloc(sizeof (no)); N->info = x; N->next = NULL; if (*L == NULL){ N -> prev = NULL; *L = N; } else{ P = *L; while (P->next != NULL){ P = P->next; } P->next = N; N->prev = P; } } int removeinicioLista(no **L){ no *P; P = *L; if (*L != NULL){ *L = P->next; if (*L != NULL) (*L)->prev = NULL; free (P); } } int removefinalLista(no **L){ no *P,*ANT; int x; if ((*L)->next == NULL){ x = (*L)->info; free(*L); *L = NULL; return (x); } else{ P = (*L)->next; ANT = *L; while (P->next != NULL){ ANT = ANT->next; P = P->next; } ANT->next = NULL; x = P->info; free(P); return (x); } } exibeLista(no *L){ no *P; P = L; while (P != NULL){ printf("\n%d",P->info); P = P->next; } } int maiornum(no *L){ no *P; P = L; int maior = P->info; while (P != NULL){ if (P->info > maior) maior = P->info; P = P->next; } return (maior); } removeitem(no **L,int x){ no *P,*PREV,*NEXT; P = *L; if (*L != NULL){ while ((P!= NULL)&&(P->info != x)) { P = P->next; } if (P == NULL){ //item nao encontrado return -999; } if (P == *L){ *L = P->next; (*L)->prev = NULL; free (P); } else{ if(P->next == NULL){ PREV = P->prev; PREV->next = NULL; free (P); } else { PREV = P->prev; NEXT = P->next; PREV->next = P->next; NEXT->prev = P->prev; free(P); } } } } inserirordem(no **L, int x){ no *P,*N,*NEXT,*PREV; N = (no *) malloc(sizeof (no)); N->info = x; if (*L == NULL){ N->prev = NULL; N->next = N; *L = N; } else{ P = *L; while ((P!= NULL)&&(P->info < x)) { P = P->next; } if (P == *L){ N->next = (*L)->next; N->prev = NULL; NEXT = (*L)->next; NEXT->prev = N; *L = N; } else{ if(P->next == NULL){ P->next = N; N->next = NULL; N->prev = P; } else { PREV = P->prev; N->next = P; N->prev = PREV; PREV->next = N; P->prev = N; } } } }
the_stack_data/12637005.c
int statlibfunc(void); int main(void) { return statlibfunc(); }
the_stack_data/92535.c
/* unhex -- convert data from hexadecimal */ #include <stdio.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) { FILE *input = stdin; int opt; char c, d; int odd = 0; while ((opt = getopt(argc, argv, "a:")) != -1) { switch (opt) { case 'a': input = fmemopen(optarg, strlen(optarg), "r"); break; default: return 2; } } if (argc > optind) { fprintf(stderr, "unhex: too many arguments\n"); return 2; } for (;;) { c = fgetc(input); if (c == EOF) break; else if (c >= '0' && c <= '9') c -= '0'; else if (c >= 'a' && c <= 'f') c -= 'a' - 10; else if (c >= 'A' && c <= 'F') c -= 'A' - 10; else continue; if (odd) fputc(d | c, stdout); else d = c << 4; odd = !odd; } if (odd) fprintf(stderr, "unhex: odd number of input nibbles\n"); return odd; }
the_stack_data/55735.c
/**************************************************************************** * Ralink Tech Inc. * Taiwan, R.O.C. * * (c) Copyright 2002, Ralink Technology, Inc. * * All rights reserved. Ralink's source code is an unpublished work and the * use of a copyright notice does not imply otherwise. This source code * contains confidential trade secret material of Ralink Tech. Any attemp * or participation in deciphering, decoding, reverse engineering or in any * way altering the source code is stricitly prohibited, unless the prior * written consent of Ralink Technology, Inc. is obtained. ***************************************************************************/ #ifdef RTMP_MAC_PCI #include "rt_config.h" static INT desc_ring_alloc(RTMP_ADAPTER *pAd, RTMP_DMABUF *pDescRing, INT size) { VOID *pci_dev = ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev; pDescRing->AllocSize = size; RtmpAllocDescBuf(pci_dev, 0, pDescRing->AllocSize, FALSE, &pDescRing->AllocVa, &pDescRing->AllocPa); if (pDescRing->AllocVa == NULL) { DBGPRINT_ERR(("Failed to allocate a big buffer\n")); return ERRLOG_OUT_OF_SHARED_MEMORY; } /* Zero init this memory block*/ NdisZeroMemory(pDescRing->AllocVa, size); return 0; } static INT desc_ring_free(RTMP_ADAPTER *pAd, RTMP_DMABUF *pDescRing) { VOID *pci_dev = ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev; if (pDescRing->AllocVa) { RtmpFreeDescBuf(pci_dev, pDescRing->AllocSize, pDescRing->AllocVa, pDescRing->AllocPa); } NdisZeroMemory(pDescRing, sizeof(RTMP_DMABUF)); return TRUE; } #ifdef RESOURCE_PRE_ALLOC VOID RTMPResetTxRxRingMemory(RTMP_ADAPTER *pAd) { int index, j; RTMP_TX_RING *pTxRing; TXD_STRUC *pTxD; RTMP_DMACB *dma_cb; #ifdef RT_BIG_ENDIAN TXD_STRUC *pDestTxD; UCHAR tx_hw_info[TXD_SIZE]; #endif /* RT_BIG_ENDIAN */ PNDIS_PACKET pPacket; rtmp_tx_swq_exit(pAd, WCID_ALL); /* Free Tx Ring Packet*/ for (index=0;index< NUM_OF_TX_RING;index++) { pTxRing = &pAd->TxRing[index]; for (j=0; j< TX_RING_SIZE; j++) { dma_cb = &pTxRing->Cell[j]; #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *)(dma_cb->AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (dma_cb->AllocVa); #endif /* RT_BIG_ENDIAN */ pPacket = dma_cb->pNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } /*Always assign pNdisPacket as NULL after clear*/ dma_cb->pNdisPacket = NULL; pPacket = dma_cb->pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } /*Always assign pNextNdisPacket as NULL after clear*/ dma_cb->pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } } #ifdef CONFIG_ANDES_SUPPORT { RTMP_CTRL_RING *pCtrlRing = &pAd->CtrlRing; RTMP_IO_READ32(pAd, pCtrlRing->hw_didx_addr, &pCtrlRing->TxDmaIdx); while (pCtrlRing->TxSwFreeIdx!= pCtrlRing->TxCpuIdx) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].AllocVa); #endif pTxD->DMADONE = 0; pPacket = pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNdisPacket; if (pPacket == NULL) { INC_RING_INDEX(pCtrlRing->TxSwFreeIdx, MGMT_RING_SIZE); continue; } if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNdisPacket = NULL; pPacket = pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNextNdisPacket = NULL; INC_RING_INDEX(pCtrlRing->TxSwFreeIdx, MGMT_RING_SIZE); #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, TRUE, TYPE_TXD); #endif } } #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC if (1 /*pAd->chipCap.hif_type == HIF_MT*/) { RTMP_BCN_RING *pBcnRing = &pAd->BcnRing; RTMP_IO_READ32(pAd, pBcnRing->hw_didx_addr, &pBcnRing->TxDmaIdx); while (pBcnRing->TxSwFreeIdx!= pBcnRing->TxDmaIdx) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (pBcnRing->Cell[pBcnRing->TxSwFreeIdx].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (pBcnRing->Cell[pBcnRing->TxSwFreeIdx].AllocVa); #endif pTxD->DMADONE = 0; pPacket = pBcnRing->Cell[pBcnRing->TxSwFreeIdx].pNdisPacket; if (pPacket == NULL) { INC_RING_INDEX(pBcnRing->TxSwFreeIdx, BCN_RING_SIZE); continue; } if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pBcnRing->Cell[pBcnRing->TxSwFreeIdx].pNdisPacket = NULL; pPacket = pBcnRing->Cell[pBcnRing->TxSwFreeIdx].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pBcnRing->Cell[pBcnRing->TxSwFreeIdx].pNextNdisPacket = NULL; INC_RING_INDEX(pBcnRing->TxSwFreeIdx, BCN_RING_SIZE); #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, TRUE, TYPE_TXD); #endif } } #endif /* MT_MAC */ for (index=0;index< NUM_OF_RX_RING;index++) { for (j = RX_RING_SIZE - 1 ; j >= 0; j--) { dma_cb = &pAd->RxRing[index].Cell[j]; if ((dma_cb->DmaBuf.AllocVa) && (dma_cb->pNdisPacket)) { PCI_UNMAP_SINGLE(pAd, dma_cb->DmaBuf.AllocPa, dma_cb->DmaBuf.AllocSize, RTMP_PCI_DMA_FROMDEVICE); RELEASE_NDIS_PACKET(pAd, dma_cb->pNdisPacket, NDIS_STATUS_SUCCESS); } } NdisZeroMemory(pAd->RxRing[index].Cell, RX_RING_SIZE * sizeof(RTMP_DMACB)); } if (pAd->FragFrame.pFragPacket) { RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, NDIS_STATUS_SUCCESS); pAd->FragFrame.pFragPacket = NULL; } NdisFreeSpinLock(&pAd->CmdQLock); } VOID RTMPFreeTxRxRingMemory(RTMP_ADAPTER *pAd) { INT num; VOID *pci_dev = ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev; DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPFreeTxRxRingMemory\n")); /* Free Rx/Mgmt Desc buffer*/ for (num = 0; num < NUM_OF_RX_RING; num++) desc_ring_free(pAd, &pAd->RxDescRing[num]); desc_ring_free(pAd, &pAd->MgmtDescRing); #ifdef CONFIG_ANDES_SUPPORT desc_ring_free(pAd, &pAd->CtrlDescRing); #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC desc_ring_free(pAd, &pAd->BcnDescRing); if (pAd->TxBmcBufSpace.AllocVa) { RTMP_FreeFirstTxBuffer(pci_dev, pAd->TxBmcBufSpace.AllocSize, FALSE, pAd->TxBmcBufSpace.AllocVa, pAd->TxBmcBufSpace.AllocPa); } NdisZeroMemory(&pAd->TxBmcBufSpace, sizeof(RTMP_DMABUF)); desc_ring_free(pAd, &pAd->TxBmcDescRing); #endif /* MT_MAC */ /* Free 1st TxBufSpace and TxDesc buffer*/ for (num = 0; num < NUM_OF_TX_RING; num++) { if (pAd->TxBufSpace[num].AllocVa) { RTMP_FreeFirstTxBuffer(pci_dev, pAd->TxBufSpace[num].AllocSize, FALSE, pAd->TxBufSpace[num].AllocVa, pAd->TxBufSpace[num].AllocPa); } NdisZeroMemory(&pAd->TxBufSpace[num], sizeof(RTMP_DMABUF)); desc_ring_free(pAd, &pAd->TxDescRing[num]); } DBGPRINT(RT_DEBUG_TRACE, ("<-- RTMPFreeTxRxRingMemory\n")); } NDIS_STATUS RTMPInitTxRxRingMemory(RTMP_ADAPTER *pAd) { INT num, index; ULONG /*RingBasePaHigh,*/ RingBasePaLow; VOID *RingBaseVa; RTMP_TX_RING *pTxRing; RTMP_RX_RING *pRxRing; RTMP_DMABUF *pDmaBuf, *pDescRing; RTMP_DMACB *dma_cb; PNDIS_PACKET pPacket; TXD_STRUC *pTxD; RXD_STRUC *pRxD; //ULONG ErrorValue = 0; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; /* Init the CmdQ and CmdQLock*/ NdisAllocateSpinLock(pAd, &pAd->CmdQLock); NdisAcquireSpinLock(&pAd->CmdQLock); RTInitializeCmdQ(&pAd->CmdQ); NdisReleaseSpinLock(&pAd->CmdQLock); /* Initialize All Tx Ring Descriptors and associated buffer memory*/ /* (5 TX rings = 4 ACs + 1 HCCA)*/ for (num = 0; num < NUM_OF_TX_RING; num++) { ULONG /*BufBasePaHigh,*/ BufBasePaLow; VOID *BufBaseVa; /* memory zero the Tx ring descriptor's memory */ pDescRing = &pAd->TxDescRing[num]; NdisZeroMemory(pDescRing->AllocVa, pDescRing->AllocSize); /* Save PA & VA for further operation*/ //RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDescRing->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pDescRing->AllocPa); RingBaseVa = pDescRing->AllocVa; /* Zero init all 1st TXBuf's memory for this TxRing*/ NdisZeroMemory(pAd->TxBufSpace[num].AllocVa, pAd->TxBufSpace[num].AllocSize); /* Save PA & VA for further operation */ //BufBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->TxBufSpace[num].AllocPa); BufBasePaLow = RTMP_GetPhysicalAddressLow (pAd->TxBufSpace[num].AllocPa); BufBaseVa = pAd->TxBufSpace[num].AllocVa; /* linking Tx Ring Descriptor and associated buffer memory */ pTxRing = &pAd->TxRing[num]; for (index = 0; index < TX_RING_SIZE; index++) { dma_cb = &pTxRing->Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init Tx Ring Size, Va, Pa variables*/ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, 0/*RingBasePaHigh*/); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Setup Tx Buffer size & address. only 802.11 header will store in this space */ pDmaBuf = &dma_cb->DmaBuf; pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE; pDmaBuf->AllocVa = BufBaseVa; RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa,0 /*BufBasePaHigh*/); RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa, BufBasePaLow); /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->SDPtr0 = BufBasePaLow; /* advance to next ring descriptor address */ pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* advance to next TxBuf address */ BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE; BufBaseVa = (PUCHAR) BufBaseVa + TX_DMA_1ST_BUFFER_SIZE; } DBGPRINT(RT_DEBUG_TRACE, ("TxRing[%d]: total %d entry initialized\n", num, index)); } /* Initialize MGMT Ring and associated buffer memory */ pDescRing = &pAd->MgmtDescRing; //RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDescRing->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pDescRing->AllocPa); RingBaseVa = pDescRing->AllocVa; NdisZeroMemory(pDescRing->AllocVa, pDescRing->AllocSize); for (index = 0; index < MGMT_RING_SIZE; index++) { dma_cb = &pAd->MgmtRing.Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init MGMT Ring Size, Va, Pa variables */ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, 0/*RingBasePaHigh*/); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address */ RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); /* no pre-allocated buffer required in MgmtRing for scatter-gather case */ } #ifdef CONFIG_ANDES_SUPPORT /* Initialize CTRL Ring and associated buffer memory */ pDescRing = &pAd->CtrlDescRing; //RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDescRing->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pDescRing->AllocPa); RingBaseVa = pDescRing->AllocVa; NdisZeroMemory(pDescRing->AllocVa, pDescRing->AllocSize); for (index = 0; index < MGMT_RING_SIZE; index++) { dma_cb = &pAd->CtrlRing.Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init Ctrl Ring Size, Va, Pa variables */ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, 0/*RingBasePaHigh*/); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address */ RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); /* no pre-allocated buffer required in CtrlRing for scatter-gather case */ } #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC if (1 /*pAd->chipCap.hif_type == HIF_MT*/) { /* Initialize CTRL Ring and associated buffer memory */ ULONG /*BufBasePaHigh,*/ BufBasePaLow; VOID *BufBaseVa; pDescRing = &pAd->BcnDescRing; //RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDescRing->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pDescRing->AllocPa); RingBaseVa = pDescRing->AllocVa; NdisZeroMemory(pDescRing->AllocVa, pDescRing->AllocSize); DBGPRINT(RT_DEBUG_OFF, ("TX_BCN DESC %p size = %ld\n", pDescRing->AllocVa, pDescRing->AllocSize)); for (index = 0; index < BCN_RING_SIZE; index++) { dma_cb = &pAd->BcnRing.Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init Ctrl Ring Size, Va, Pa variables */ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, 0/*RingBasePaHigh*/); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address */ RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); /* no pre-allocated buffer required in CtrlRing for scatter-gather case */ } /* memory zero the Tx BMC ring descriptor's memory */ pDescRing = &pAd->TxBmcDescRing; NdisZeroMemory(pDescRing->AllocVa, pDescRing->AllocSize); /* Save PA & VA for further operation*/ //RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDescRing->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pDescRing->AllocPa); RingBaseVa = pDescRing->AllocVa; /* Zero init all 1st TXBuf's memory for this TxRing*/ NdisZeroMemory(pAd->TxBmcBufSpace.AllocVa, pAd->TxBmcBufSpace.AllocSize); /* Save PA & VA for further operation */ //BufBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->TxBmcBufSpace.AllocPa); BufBasePaLow = RTMP_GetPhysicalAddressLow (pAd->TxBmcBufSpace.AllocPa); BufBaseVa = pAd->TxBmcBufSpace.AllocVa; /* linking Tx Ring Descriptor and associated buffer memory */ pTxRing = &pAd->TxBmcRing; for (index = 0; index < TX_RING_SIZE; index++) { dma_cb = &pTxRing->Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init Tx Ring Size, Va, Pa variables*/ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, 0/*RingBasePaHigh*/); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Setup Tx Buffer size & address. only 802.11 header will store in this space */ pDmaBuf = &dma_cb->DmaBuf; pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE; pDmaBuf->AllocVa = BufBaseVa; RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa,0 /*BufBasePaHigh*/); RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa, BufBasePaLow); /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->SDPtr0 = BufBasePaLow; /* advance to next ring descriptor address */ pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* advance to next TxBuf address */ BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE; BufBaseVa = (PUCHAR) BufBaseVa + TX_DMA_1ST_BUFFER_SIZE; } } #endif /* MT_MAC */ /* Initialize Rx Ring and associated buffer memory */ for (num = 0; num < NUM_OF_RX_RING; num++) { pDescRing = &pAd->RxDescRing[num]; pRxRing = &pAd->RxRing[num]; NdisZeroMemory(pDescRing->AllocVa, pDescRing->AllocSize); DBGPRINT(RT_DEBUG_OFF, ("RX[%d] DESC %p size = %ld\n", num, pDescRing->AllocVa, pDescRing->AllocSize)); /* Save PA & VA for further operation */ //RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDescRing->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pDescRing->AllocPa); RingBaseVa = pDescRing->AllocVa; /* Linking Rx Ring and associated buffer memory */ for (index = 0; index < RX_RING_SIZE; index++) { dma_cb = &pRxRing->Cell[index]; /* Init RX Ring Size, Va, Pa variables*/ dma_cb->AllocSize = RXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, 0/*RingBasePaHigh*/); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow);; /* Offset to next ring descriptor address */ RingBasePaLow += RXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + RXD_SIZE; /* Setup Rx associated Buffer size & allocate share memory */ pDmaBuf = &dma_cb->DmaBuf; pDmaBuf->AllocSize = RX_BUFFER_AGGRESIZE; pPacket = RTMP_AllocateRxPacketBuffer( pAd, ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pDmaBuf->AllocSize, FALSE, &pDmaBuf->AllocVa, &pDmaBuf->AllocPa); /* keep allocated rx packet */ dma_cb->pNdisPacket = pPacket; /* Error handling*/ if (pDmaBuf->AllocVa == NULL) { //ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; DBGPRINT_ERR(("Failed to allocate RxRing's 1st buffer\n")); Status = NDIS_STATUS_RESOURCES; break; } /* Zero init this memory block */ //NdisZeroMemory(pDmaBuf->AllocVa, pDmaBuf->AllocSize); /* Write RxD buffer address & allocated buffer length */ pRxD = (RXD_STRUC *)dma_cb->AllocVa; pRxD->SDP0 = RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa); pRxD->DDONE = 0; pRxD->SDL0 = pDmaBuf->AllocSize; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pRxD, TYPE_RXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pRxD, dma_cb->AllocSize); } } NdisZeroMemory(&pAd->FragFrame, sizeof(FRAGMENT_FRAME)); pAd->FragFrame.pFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); if (pAd->FragFrame.pFragPacket == NULL) Status = NDIS_STATUS_RESOURCES; /* Initialize all transmit related software queues */ rtmp_tx_swq_init(pAd); for(index = 0; index < NUM_OF_TX_RING; index++) { /* Init TX rings index pointer */ pAd->TxRing[index].TxSwFreeIdx = 0; pAd->TxRing[index].TxCpuIdx = 0; } /* Init RX Ring index pointer */ for (index = 0; index < NUM_OF_RX_RING; index++) { pAd->RxRing[index].RxSwReadIdx = 0; pAd->RxRing[index].RxCpuIdx = RX_RING_SIZE - 1; } /* init MGMT ring index pointer */ pAd->MgmtRing.TxSwFreeIdx = 0; pAd->MgmtRing.TxCpuIdx = 0; #ifdef CONFIG_ANDES_SUPPORT /* init CTRL ring index pointer */ pAd->CtrlRing.TxSwFreeIdx = 0; pAd->CtrlRing.TxCpuIdx = 0; #endif /* CONFIG_ANDES_SUPPORT */ pAd->PrivateInfo.TxRingFullCnt = 0; return Status; } /* ======================================================================== Routine Description: Allocate DMA memory blocks for send, receive Arguments: Adapter Pointer to our adapter Return Value: NDIS_STATUS_SUCCESS NDIS_STATUS_FAILURE NDIS_STATUS_RESOURCES IRQL = PASSIVE_LEVEL Note: ======================================================================== */ NDIS_STATUS RTMPAllocTxRxRingMemory(RTMP_ADAPTER *pAd) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; INT num; ULONG ErrorValue = 0; VOID *pci_dev = ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev; DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPAllocTxRxRingMemory\n")); do { /* Allocate all ring descriptors, include TxD, RxD, MgmtD. Although each size is different, to prevent cacheline and alignment issue, I intentional set them all to 64 bytes. */ for (num = 0; num < NUM_OF_TX_RING; num++) { /* Allocate Tx ring descriptor's memory (5 TX rings = 4 ACs + 1 HCCA)*/ desc_ring_alloc(pAd, &pAd->TxDescRing[num], TX_RING_SIZE * TXD_SIZE); if (pAd->TxDescRing[num].AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("TxRing[%d]: total %d bytes allocated\n", num, (INT)pAd->TxDescRing[num].AllocSize)); /* Allocate all 1st TXBuf's memory for this TxRing */ pAd->TxBufSpace[num].AllocSize = TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE; RTMP_AllocateFirstTxBuffer( pci_dev, num, pAd->TxBufSpace[num].AllocSize, FALSE, &pAd->TxBufSpace[num].AllocVa, &pAd->TxBufSpace[num].AllocPa); if (pAd->TxBufSpace[num].AllocVa == NULL) { ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; DBGPRINT_ERR(("Failed to allocate a big buffer\n")); Status = NDIS_STATUS_RESOURCES; break; } } if (Status == NDIS_STATUS_RESOURCES) break; /* Alloc MGMT ring desc buffer except Tx ring allocated eariler */ desc_ring_alloc(pAd, &pAd->MgmtDescRing, MGMT_RING_SIZE * TXD_SIZE); if (pAd->MgmtDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("MGMT Ring: total %d bytes allocated\n", (INT)pAd->MgmtDescRing.AllocSize)); #ifdef CONFIG_ANDES_SUPPORT /* Alloc CTRL ring desc buffer except Tx ring allocated eariler */ desc_ring_alloc(pAd, &pAd->CtrlDescRing, MGMT_RING_SIZE * TXD_SIZE); if (pAd->CtrlDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("CTRL Ring: total %d bytes allocated\n", (INT)pAd->CtrlDescRing.AllocSize)); #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC if (1 /*pAd->chipCap.hif_type == HIF_MT*/) { /* Alloc Beacon ring desc buffer */ desc_ring_alloc(pAd, &pAd->BcnDescRing, BCN_RING_SIZE * TXD_SIZE); if (pAd->BcnDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("Beacon Ring: total %d bytes allocated\n", (INT)pAd->BcnDescRing.AllocSize)); /* Allocate Tx ring descriptor's memory (BMC)*/ desc_ring_alloc(pAd, &pAd->TxBmcDescRing, TX_RING_SIZE * TXD_SIZE); if (pAd->TxBmcDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("TxBmcRing: total %d bytes allocated\n", (INT)pAd->TxBmcDescRing.AllocSize)); /* Allocate all 1st TXBuf's memory for this TxRing */ pAd->TxBmcBufSpace.AllocSize = TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE; RTMP_AllocateFirstTxBuffer( pci_dev, 0, pAd->TxBmcBufSpace.AllocSize, FALSE, &pAd->TxBmcBufSpace.AllocVa, &pAd->TxBmcBufSpace.AllocPa); if (pAd->TxBmcBufSpace.AllocVa == NULL) { ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; DBGPRINT_ERR(("Failed to allocate a big buffer\n")); Status = NDIS_STATUS_RESOURCES; break; } if (Status == NDIS_STATUS_RESOURCES) break; } #endif /* MT_MAC */ /* Alloc RX ring desc memory except Tx ring allocated eariler */ for (num = 0; num < NUM_OF_RX_RING; num++) { desc_ring_alloc(pAd, &pAd->RxDescRing[num], RX_RING_SIZE * RXD_SIZE); if (pAd->RxDescRing[num].AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("Rx[%d] Ring: total %d bytes allocated\n", num, (INT)pAd->RxDescRing[num].AllocSize)); } } while (FALSE); if (Status != NDIS_STATUS_SUCCESS) { /* Log error inforamtion*/ NdisWriteErrorLogEntry( pAd->AdapterHandle, NDIS_ERROR_CODE_OUT_OF_RESOURCES, 1, ErrorValue); } DBGPRINT_S(("<-- RTMPAllocTxRxRingMemory, Status=%x, ErrorValue=%lux\n", Status,ErrorValue)); return Status; } #else /* ======================================================================== Routine Description: Allocate DMA memory blocks for send, receive Arguments: Adapter Pointer to our adapter Return Value: NDIS_STATUS_SUCCESS NDIS_STATUS_FAILURE NDIS_STATUS_RESOURCES IRQL = PASSIVE_LEVEL Note: ======================================================================== */ NDIS_STATUS RTMPAllocTxRxRingMemory(RTMP_ADAPTER *pAd) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; ULONG RingBasePaHigh, RingBasePaLow; PVOID RingBaseVa; INT index, num; TXD_STRUC *pTxD; RXD_STRUC *pRxD; ULONG ErrorValue = 0; RTMP_TX_RING *pTxRing; RTMP_DMABUF *pDmaBuf; RTMP_DMACB *dma_cb; PNDIS_PACKET pPacket; DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n")); /* Init the CmdQ and CmdQLock*/ NdisAllocateSpinLock(pAd, &pAd->CmdQLock); NdisAcquireSpinLock(&pAd->CmdQLock); RTInitializeCmdQ(&pAd->CmdQ); NdisReleaseSpinLock(&pAd->CmdQLock); do { /* Allocate all ring descriptors, include TxD, RxD, MgmtD. Although each size is different, to prevent cacheline and alignment issue, I intentional set them all to 64 bytes */ for (num=0; num<NUM_OF_TX_RING; num++) { ULONG BufBasePaHigh; ULONG BufBasePaLow; PVOID BufBaseVa; /* Allocate Tx ring descriptor's memory (5 TX rings = 4 ACs + 1 HCCA) */ desc_ring_alloc(pAd, &pAd->TxDescRing[num], TX_RING_SIZE * TXD_SIZE); if (pAd->TxDescRing[num].AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } pDmaBuf = &pAd->TxDescRing[num]; DBGPRINT(RT_DEBUG_TRACE, ("TxDescRing[%p]: total %d bytes allocated\n", pDmaBuf->AllocVa, (INT)pDmaBuf->AllocSize)); /* Save PA & VA for further operation*/ RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDmaBuf->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa); RingBaseVa = pDmaBuf->AllocVa; /* Allocate all 1st TXBuf's memory for this TxRing */ pAd->TxBufSpace[num].AllocSize = TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE; RTMP_AllocateFirstTxBuffer( ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, num, pAd->TxBufSpace[num].AllocSize, FALSE, &pAd->TxBufSpace[num].AllocVa, &pAd->TxBufSpace[num].AllocPa); if (pAd->TxBufSpace[num].AllocVa == NULL) { ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; DBGPRINT_ERR(("Failed to allocate a big buffer\n")); Status = NDIS_STATUS_RESOURCES; break; } /* Zero init this memory block*/ NdisZeroMemory(pAd->TxBufSpace[num].AllocVa, pAd->TxBufSpace[num].AllocSize); /* Save PA & VA for further operation*/ BufBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->TxBufSpace[num].AllocPa); BufBasePaLow = RTMP_GetPhysicalAddressLow (pAd->TxBufSpace[num].AllocPa); BufBaseVa = pAd->TxBufSpace[num].AllocVa; /* Initialize Tx Ring Descriptor and associated buffer memory */ pTxRing = &pAd->TxRing[num]; for (index = 0; index < TX_RING_SIZE; index++) { dma_cb = &pTxRing->Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init Tx Ring Size, Va, Pa variables */ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, RingBasePaHigh); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Setup Tx Buffer size & address. only 802.11 header will store in this space*/ pDmaBuf = &dma_cb->DmaBuf; pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE; pDmaBuf->AllocVa = BufBaseVa; RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa, BufBasePaHigh); RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa, BufBasePaLow); /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->SDPtr0 = BufBasePaLow; /* advance to next ring descriptor address */ pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* advance to next TxBuf address */ BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE; BufBaseVa = (PUCHAR) BufBaseVa + TX_DMA_1ST_BUFFER_SIZE; } DBGPRINT(RT_DEBUG_TRACE, ("TxRing[%d]: total %d entry allocated\n", num, index)); } if (Status == NDIS_STATUS_RESOURCES) break; /* Allocate MGMT ring descriptor's memory except Tx ring which allocated eariler */ desc_ring_alloc(pAd, &pAd->MgmtDescRing, MGMT_RING_SIZE * TXD_SIZE); if (pAd->MgmtDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("MgmtDescRing[%p]: total %d bytes allocated\n", pAd->MgmtDescRing.AllocVa, (INT)pAd->MgmtDescRing.AllocSize)); /* Save PA & VA for further operation*/ RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->MgmtDescRing.AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow(pAd->MgmtDescRing.AllocPa); RingBaseVa = pAd->MgmtDescRing.AllocVa; /* Initialize MGMT Ring and associated buffer memory */ for (index = 0; index < MGMT_RING_SIZE; index++) { dma_cb = &pAd->MgmtRing.Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init MGMT Ring Size, Va, Pa variables*/ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, RingBasePaHigh); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address*/ RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* link the pre-allocated TxBuf to TXD*/ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); /* no pre-allocated buffer required in MgmtRing for scatter-gather case*/ } DBGPRINT(RT_DEBUG_TRACE, ("MGMT Ring: total %d entry allocated\n", index)); #ifdef CONFIG_ANDES_SUPPORT /* Allocate CTRL ring descriptor's memory except Tx ring which allocated eariler */ desc_ring_alloc(pAd, &pAd->CtrlDescRing, MGMT_RING_SIZE * TXD_SIZE); if (pAd->CtrlDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("CtrlDescRing[%p]: total %d bytes allocated\n", pAd->CtrlDescRing.AllocVa, (INT)pAd->CtrlDescRing.AllocSize)); /* Save PA & VA for further operation*/ RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->CtrlDescRing.AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pAd->CtrlDescRing.AllocPa); RingBaseVa = pAd->CtrlDescRing.AllocVa; /* Initialize CTRL Ring and associated buffer memory */ for (index = 0; index < MGMT_RING_SIZE; index++) { dma_cb = &pAd->CtrlRing.Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init CTRL Ring Size, Va, Pa variables*/ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, RingBasePaHigh); RTMP_SetPhysicalAddressLow(dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address*/ RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* link the pre-allocated TxBuf to TXD*/ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); /* no pre-allocated buffer required in CtrlRing for scatter-gather case*/ } DBGPRINT(RT_DEBUG_TRACE, ("CTRL Ring: total %d entry allocated\n", index)); #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC if (1/* pAd->chipCap.hif_type == HIF_MT */) { /* Allocate Beacon ring descriptor's memory */ ULONG BufBasePaHigh; ULONG BufBasePaLow; PVOID BufBaseVa; desc_ring_alloc(pAd, &pAd->BcnDescRing, BCN_RING_SIZE * TXD_SIZE); if (pAd->BcnDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_TRACE, ("BcnDescRing[%p]: total %d bytes allocated\n", pAd->BcnDescRing.AllocVa, (INT)pAd->BcnDescRing.AllocSize)); /* Save PA & VA for further operation*/ RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->BcnDescRing.AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pAd->BcnDescRing.AllocPa); RingBaseVa = pAd->BcnDescRing.AllocVa; /* Initialize Beacon Ring and associated buffer memory */ for (index = 0; index < BCN_RING_SIZE; index++) { dma_cb = &pAd->BcnRing.Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init CTRL Ring Size, Va, Pa variables*/ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, RingBasePaHigh); RTMP_SetPhysicalAddressLow(dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address*/ RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* link the pre-allocated TxBuf to TXD*/ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); /* no pre-allocated buffer required in CtrlRing for scatter-gather case*/ } DBGPRINT(RT_DEBUG_TRACE, ("Bcn Ring: total %d entry allocated\n", index)); /* Allocate Tx ring descriptor's memory (BMC) */ desc_ring_alloc(pAd, &pAd->TxBmcDescRing, TX_RING_SIZE * TXD_SIZE); if (pAd->TxBmcDescRing.AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } pDmaBuf = &pAd->TxBmcDescRing; DBGPRINT(RT_DEBUG_TRACE, ("TxBmcDescRing[%p]: total %d bytes allocated\n", pDmaBuf->AllocVa, (INT)pDmaBuf->AllocSize)); /* Save PA & VA for further operation*/ RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pDmaBuf->AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa); RingBaseVa = pDmaBuf->AllocVa; /* Allocate all 1st TXBuf's memory for this TxRing */ pAd->TxBmcBufSpace.AllocSize = TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE; RTMP_AllocateFirstTxBuffer( ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, 0, pAd->TxBmcBufSpace.AllocSize, FALSE, &pAd->TxBmcBufSpace.AllocVa, &pAd->TxBmcBufSpace.AllocPa); if (pAd->TxBmcBufSpace.AllocVa == NULL) { ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; DBGPRINT_ERR(("Failed to allocate a big buffer\n")); Status = NDIS_STATUS_RESOURCES; break; } /* Zero init this memory block*/ NdisZeroMemory(pAd->TxBmcBufSpace.AllocVa, pAd->TxBmcBufSpace.AllocSize); /* Save PA & VA for further operation*/ BufBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->TxBmcBufSpace.AllocPa); BufBasePaLow = RTMP_GetPhysicalAddressLow (pAd->TxBmcBufSpace.AllocPa); BufBaseVa = pAd->TxBmcBufSpace.AllocVa; /* Initialize Tx Ring Descriptor and associated buffer memory */ pTxRing = &pAd->TxBmcRing; for (index = 0; index < TX_RING_SIZE; index++) { dma_cb = &pTxRing->Cell[index]; dma_cb->pNdisPacket = NULL; dma_cb->pNextNdisPacket = NULL; /* Init Tx Ring Size, Va, Pa variables */ dma_cb->AllocSize = TXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, RingBasePaHigh); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Setup Tx Buffer size & address. only 802.11 header will store in this space*/ pDmaBuf = &dma_cb->DmaBuf; pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE; pDmaBuf->AllocVa = BufBaseVa; RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa, BufBasePaHigh); RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa, BufBasePaLow); /* link the pre-allocated TxBuf to TXD */ pTxD = (TXD_STRUC *)dma_cb->AllocVa; pTxD->SDPtr0 = BufBasePaLow; /* advance to next ring descriptor address */ pTxD->DMADONE = 1; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pTxD, dma_cb->AllocSize); RingBasePaLow += TXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + TXD_SIZE; /* advance to next TxBuf address */ BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE; BufBaseVa = (PUCHAR) BufBaseVa + TX_DMA_1ST_BUFFER_SIZE; } if (Status == NDIS_STATUS_RESOURCES) break; } #endif /* MT_MAC */ for (num = 0; num < NUM_OF_RX_RING; num++) { /* Alloc RxRingDesc memory except Tx ring allocated eariler */ desc_ring_alloc(pAd, &pAd->RxDescRing[num], RX_RING_SIZE * RXD_SIZE); if (pAd->RxDescRing[num].AllocVa == NULL) { Status = NDIS_STATUS_RESOURCES; break; } DBGPRINT(RT_DEBUG_OFF, ("RxDescRing[%p]: total %d bytes allocated\n", pAd->RxDescRing[num].AllocVa, (INT)pAd->RxDescRing[num].AllocSize)); /* Initialize Rx Ring and associated buffer memory */ RingBasePaHigh = RTMP_GetPhysicalAddressHigh(pAd->RxDescRing[num].AllocPa); RingBasePaLow = RTMP_GetPhysicalAddressLow (pAd->RxDescRing[num].AllocPa); RingBaseVa = pAd->RxDescRing[num].AllocVa; for (index = 0; index < RX_RING_SIZE; index++) { dma_cb = &pAd->RxRing[num].Cell[index]; /* Init RX Ring Size, Va, Pa variables*/ dma_cb->AllocSize = RXD_SIZE; dma_cb->AllocVa = RingBaseVa; RTMP_SetPhysicalAddressHigh(dma_cb->AllocPa, RingBasePaHigh); RTMP_SetPhysicalAddressLow (dma_cb->AllocPa, RingBasePaLow); /* Offset to next ring descriptor address */ RingBasePaLow += RXD_SIZE; RingBaseVa = (PUCHAR) RingBaseVa + RXD_SIZE; /* Setup Rx associated Buffer size & allocate share memory*/ pDmaBuf = &dma_cb->DmaBuf; pDmaBuf->AllocSize = RX_BUFFER_AGGRESIZE; pPacket = RTMP_AllocateRxPacketBuffer( pAd, ((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pDmaBuf->AllocSize, FALSE, &pDmaBuf->AllocVa, &pDmaBuf->AllocPa); /* keep allocated rx packet */ dma_cb->pNdisPacket = pPacket; if (pDmaBuf->AllocVa == NULL) { ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; DBGPRINT_ERR(("Failed to allocate RxRing's 1st buffer\n")); Status = NDIS_STATUS_RESOURCES; break; } /* Zero init this memory block*/ NdisZeroMemory(pDmaBuf->AllocVa, pDmaBuf->AllocSize); /* Write RxD buffer address & allocated buffer length*/ pRxD = (RXD_STRUC *)dma_cb->AllocVa; pRxD->SDP0 = RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa); pRxD->SDL0 = pDmaBuf->AllocSize; pRxD->DDONE = 0; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pRxD, TYPE_RXD); #endif /* flush dcache if no consistent memory is supported */ RTMP_DCACHE_FLUSH(pRxD, dma_cb->AllocSize); } DBGPRINT(RT_DEBUG_TRACE, ("Rx[%d] Ring: total %d entry allocated\n", num, index)); } } while (FALSE); NdisZeroMemory(&pAd->FragFrame, sizeof(FRAGMENT_FRAME)); pAd->FragFrame.pFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); if (pAd->FragFrame.pFragPacket == NULL) Status = NDIS_STATUS_RESOURCES; if (Status != NDIS_STATUS_SUCCESS) { /* Log error inforamtion*/ NdisWriteErrorLogEntry( pAd->AdapterHandle, NDIS_ERROR_CODE_OUT_OF_RESOURCES, 1, ErrorValue); } /* Initialize all transmit related software queues */ /* Init TX rings index pointer*/ rtmp_tx_swq_init(pAd); for(index = 0; index < NUM_OF_TX_RING; index++) { pAd->TxRing[index].TxSwFreeIdx = 0; pAd->TxRing[index].TxCpuIdx = 0; } /* init MGMT ring index pointer*/ pAd->MgmtRing.TxSwFreeIdx = 0; pAd->MgmtRing.TxCpuIdx = 0; #ifdef CONFIG_ANDES_SUPPORT /* init CTRL ring index pointer*/ pAd->CtrlRing.TxSwFreeIdx = 0; pAd->CtrlRing.TxCpuIdx = 0; #endif /* CONFIG_ANDES_SUPPORT */ /* Init RX Ring index pointer*/ for(index = 0; index < NUM_OF_RX_RING; index++) { pAd->RxRing[index].RxSwReadIdx = 0; pAd->RxRing[index].RxCpuIdx = RX_RING_SIZE - 1; } pAd->PrivateInfo.TxRingFullCnt = 0; DBGPRINT_S(("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status)); return Status; } VOID RTMPFreeTxRxRingMemory(RTMP_ADAPTER *pAd) { int index, num , j; RTMP_TX_RING *pTxRing; TXD_STRUC *pTxD; #ifdef RT_BIG_ENDIAN TXD_STRUC *pDestTxD; UCHAR tx_hw_info[TXD_SIZE]; #endif /* RT_BIG_ENDIAN */ PNDIS_PACKET pPacket; RTMP_DMACB *dma_cb; DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPFreeTxRxRingMemory\n")); rtmp_tx_swq_exit(pAd, WCID_ALL); /* Free Tx Ring Packet*/ for (index=0;index< NUM_OF_TX_RING;index++) { pTxRing = &pAd->TxRing[index]; for (j=0; j< TX_RING_SIZE; j++) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (pTxRing->Cell[j].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (pTxRing->Cell[j].AllocVa); #endif /* RT_BIG_ENDIAN */ pPacket = pTxRing->Cell[j].pNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } /*Always assign pNdisPacket as NULL after clear*/ pTxRing->Cell[j].pNdisPacket = NULL; pPacket = pTxRing->Cell[j].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } /*Always assign pNextNdisPacket as NULL after clear*/ pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } } { RTMP_MGMT_RING *pMgmtRing = &pAd->MgmtRing; NdisAcquireSpinLock(&pAd->MgmtRingLock); RTMP_IO_READ32(pAd, pMgmtRing->hw_didx_addr, &pMgmtRing->TxDmaIdx); while (pMgmtRing->TxSwFreeIdx!= pMgmtRing->TxDmaIdx) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (pMgmtRing->Cell[pAd->MgmtRing.TxSwFreeIdx].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (pMgmtRing->Cell[pAd->MgmtRing.TxSwFreeIdx].AllocVa); #endif pTxD->DMADONE = 0; pPacket = pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNdisPacket; if (pPacket == NULL) { INC_RING_INDEX(pMgmtRing->TxSwFreeIdx, MGMT_RING_SIZE); continue; } if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNdisPacket = NULL; pPacket = pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNextNdisPacket = NULL; INC_RING_INDEX(pMgmtRing->TxSwFreeIdx, MGMT_RING_SIZE); #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, TRUE, TYPE_TXD); #endif } NdisReleaseSpinLock(&pAd->MgmtRingLock); } #ifdef CONFIG_ANDES_SUPPORT { RTMP_CTRL_RING *pCtrlRing = &pAd->CtrlRing; NdisAcquireSpinLock(&pAd->CtrlRingLock); RTMP_IO_READ32(pAd, pCtrlRing->hw_didx_addr, &pCtrlRing->TxDmaIdx); while (pCtrlRing->TxSwFreeIdx!= pCtrlRing->TxDmaIdx) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].AllocVa); #endif pTxD->DMADONE = 0; pPacket = pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNdisPacket; if (pPacket == NULL) { INC_RING_INDEX(pCtrlRing->TxSwFreeIdx, MGMT_RING_SIZE); continue; } if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNdisPacket = NULL; pPacket = pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } pCtrlRing->Cell[pCtrlRing->TxSwFreeIdx].pNextNdisPacket = NULL; INC_RING_INDEX(pCtrlRing->TxSwFreeIdx, MGMT_RING_SIZE); #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, TRUE, TYPE_TXD); #endif } NdisReleaseSpinLock(&pAd->CtrlRingLock); } #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC if (1 /*pAd->chipCap.hif_type == HIF_MT*/) { RTMP_BCN_RING *pBcnRing = &pAd->BcnRing; RTMP_DMACB *dma_cell = &pAd->BcnRing.Cell[0]; RTMP_SEM_LOCK(&pAd->BcnRingLock); //NdisAcquireSpinLock(&pAd->BcnRingLock); RTMP_IO_READ32(pAd, pBcnRing->hw_didx_addr, &pBcnRing->TxDmaIdx); while (pBcnRing->TxSwFreeIdx!= pBcnRing->TxDmaIdx) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (dma_cell[pBcnRing->TxSwFreeIdx].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (dma_cell[pBcnRing->TxSwFreeIdx].AllocVa); #endif pTxD->DMADONE = 0; pPacket = dma_cell[pBcnRing->TxSwFreeIdx].pNdisPacket; if (pPacket == NULL) { INC_RING_INDEX(pBcnRing->TxSwFreeIdx, BCN_RING_SIZE); continue; } if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } dma_cell[pBcnRing->TxSwFreeIdx].pNdisPacket = NULL; pPacket = dma_cell[pBcnRing->TxSwFreeIdx].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } dma_cell[pBcnRing->TxSwFreeIdx].pNextNdisPacket = NULL; INC_RING_INDEX(pBcnRing->TxSwFreeIdx, BCN_RING_SIZE); #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, TRUE, TYPE_TXD); #endif } RTMP_SEM_UNLOCK(&pAd->BcnRingLock); //NdisReleaseSpinLock(&pAd->BcnRingLock); /* Free Tx BMC Ring Packet*/ pTxRing = &pAd->TxBmcRing; for (j=0; j< TX_RING_SIZE; j++) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) (pTxRing->Cell[j].AllocVa); NdisMoveMemory(&tx_hw_info[0], (UCHAR *)pDestTxD, TXD_SIZE); pTxD = (TXD_STRUC *)&tx_hw_info[0]; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) (pTxRing->Cell[j].AllocVa); #endif /* RT_BIG_ENDIAN */ pPacket = pTxRing->Cell[j].pNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } /*Always assign pNdisPacket as NULL after clear*/ pTxRing->Cell[j].pNdisPacket = NULL; pPacket = pTxRing->Cell[j].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); } /*Always assign pNextNdisPacket as NULL after clear*/ pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } if (pAd->TxBmcBufSpace.AllocVa) { RTMP_FreeFirstTxBuffer(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->TxBmcBufSpace.AllocSize, FALSE, pAd->TxBmcBufSpace.AllocVa, pAd->TxBmcBufSpace.AllocPa); } NdisZeroMemory(&pAd->TxBmcBufSpace, sizeof(RTMP_DMABUF)); if (pAd->TxBmcDescRing.AllocVa) { RtmpFreeDescBuf(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->TxBmcDescRing.AllocSize, pAd->TxBmcDescRing.AllocVa, pAd->TxBmcDescRing.AllocPa); } NdisZeroMemory(&pAd->TxBmcDescRing, sizeof(RTMP_DMABUF)); } #endif /* MT_MAC */ for (j = 0; j < NUM_OF_RX_RING; j++) { for (index = RX_RING_SIZE - 1 ; index >= 0; index--) { dma_cb = &pAd->RxRing[j].Cell[index]; if ((dma_cb->DmaBuf.AllocVa) && (dma_cb->pNdisPacket)) { PCI_UNMAP_SINGLE(pAd, dma_cb->DmaBuf.AllocPa, dma_cb->DmaBuf.AllocSize, RTMP_PCI_DMA_FROMDEVICE); RELEASE_NDIS_PACKET(pAd, dma_cb->pNdisPacket, NDIS_STATUS_SUCCESS); } } NdisZeroMemory(pAd->RxRing[j].Cell, RX_RING_SIZE * sizeof(RTMP_DMACB)); if (pAd->RxDescRing[j].AllocVa) RtmpFreeDescBuf(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->RxDescRing[j].AllocSize, pAd->RxDescRing[j].AllocVa, pAd->RxDescRing[j].AllocPa); NdisZeroMemory(&pAd->RxDescRing[j], sizeof(RTMP_DMABUF)); } if (pAd->MgmtDescRing.AllocVa) { RtmpFreeDescBuf(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->MgmtDescRing.AllocSize, pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocPa); } NdisZeroMemory(&pAd->MgmtDescRing, sizeof(RTMP_DMABUF)); #ifdef CONFIG_ANDES_SUPPORT if (pAd->CtrlDescRing.AllocVa) { RtmpFreeDescBuf(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->CtrlDescRing.AllocSize, pAd->CtrlDescRing.AllocVa, pAd->CtrlDescRing.AllocPa); } NdisZeroMemory(&pAd->CtrlDescRing, sizeof(RTMP_DMABUF)); #endif /* CONFIG_ANDES_SUPPORT */ for (num = 0; num < NUM_OF_TX_RING; num++) { if (pAd->TxBufSpace[num].AllocVa) { RTMP_FreeFirstTxBuffer(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->TxBufSpace[num].AllocSize, FALSE, pAd->TxBufSpace[num].AllocVa, pAd->TxBufSpace[num].AllocPa); } NdisZeroMemory(&pAd->TxBufSpace[num], sizeof(RTMP_DMABUF)); if (pAd->TxDescRing[num].AllocVa) { RtmpFreeDescBuf(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, pAd->TxDescRing[num].AllocSize, pAd->TxDescRing[num].AllocVa, pAd->TxDescRing[num].AllocPa); } NdisZeroMemory(&pAd->TxDescRing[num], sizeof(RTMP_DMABUF)); } if (pAd->FragFrame.pFragPacket) { RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, NDIS_STATUS_SUCCESS); pAd->FragFrame.pFragPacket = NULL; } NdisFreeSpinLock(&pAd->CmdQLock); DBGPRINT(RT_DEBUG_TRACE, ("<-- RTMPFreeTxRxRingMemory\n")); } #endif /* RESOURCE_PRE_ALLOC */ VOID AsicInitTxRxRing(RTMP_ADAPTER *pAd) { #ifdef RLT_MAC if (pAd->chipCap.hif_type == HIF_RLT) rlt_asic_init_txrx_ring(pAd); #endif /* RLT_MAC */ #ifdef RTMP_MAC if (pAd->chipCap.hif_type == HIF_RTMP) rtmp_asic_init_txrx_ring(pAd); #endif /* RTMP_MAC */ #ifdef MT_MAC if (pAd->chipCap.hif_type == HIF_MT) mt_asic_init_txrx_ring(pAd); #endif /* MT_MAC */ } /* ======================================================================== Routine Description: Reset NIC Asics. Call after rest DMA. So reset TX_CTX_IDX to zero. Arguments: Adapter Pointer to our adapter Return Value: None IRQL = PASSIVE_LEVEL IRQL = DISPATCH_LEVEL Note: Reset NIC to initial state AS IS system boot up time. ======================================================================== */ VOID RTMPRingCleanUp(RTMP_ADAPTER *pAd, UCHAR RingType) { TXD_STRUC *pTxD; RXD_STRUC *pRxD; #ifdef RT_BIG_ENDIAN TXD_STRUC *pDestTxD, TxD; RXD_STRUC *pDestRxD, RxD; #endif /* RT_BIG_ENDIAN */ //QUEUE_ENTRY *pEntry; PNDIS_PACKET pPacket; RTMP_TX_RING *pTxRing; ULONG IrqFlags = 0; int i, ring_id; /* We have to clean all descriptors in case some error happened with reset */ DBGPRINT(RT_DEBUG_OFF,("RTMPRingCleanUp(RingIdx=%d, Pending-NDIS=%ld)\n", RingType, pAd->RalinkCounters.PendingNdisPacketCount)); switch (RingType) { case QID_AC_BK: case QID_AC_BE: case QID_AC_VI: case QID_AC_VO: case QID_HCCA: pTxRing = &pAd->TxRing[RingType]; RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); for (i=0; i<TX_RING_SIZE; i++) /* We have to scan all TX ring*/ { pTxD = (TXD_STRUC *) pTxRing->Cell[i].AllocVa; pPacket = (PNDIS_PACKET) pTxRing->Cell[i].pNdisPacket; /* release scatter-and-gather NDIS_PACKET*/ if (pPacket) { RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); pTxRing->Cell[i].pNdisPacket = NULL; } pPacket = (PNDIS_PACKET) pTxRing->Cell[i].pNextNdisPacket; /* release scatter-and-gather NDIS_PACKET*/ if (pPacket) { RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); pTxRing->Cell[i].pNextNdisPacket = NULL; } } RTMP_IO_READ32(pAd, pTxRing->hw_didx_addr, &pTxRing->TxDmaIdx); pTxRing->TxSwFreeIdx = pTxRing->TxDmaIdx; pTxRing->TxCpuIdx = pTxRing->TxDmaIdx; RTMP_IO_WRITE32(pAd, pTxRing->hw_cidx_addr, pTxRing->TxCpuIdx); RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); //rtmp_tx_swq_exit(pAd, WCID_ALL); break; case QID_MGMT: RTMP_IRQ_LOCK(&pAd->MgmtRingLock, IrqFlags); for (i=0; i<MGMT_RING_SIZE; i++) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) pAd->MgmtRing.Cell[i].AllocVa; TxD = *pDestTxD; pTxD = &TxD; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) pAd->MgmtRing.Cell[i].AllocVa; #endif /* RT_BIG_ENDIAN */ pPacket = (PNDIS_PACKET) pAd->MgmtRing.Cell[i].pNdisPacket; /* rlease scatter-and-gather NDIS_PACKET*/ if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->MgmtRing.Cell[i].pNdisPacket = NULL; pPacket = (PNDIS_PACKET) pAd->MgmtRing.Cell[i].pNextNdisPacket; /* release scatter-and-gather NDIS_PACKET*/ if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->MgmtRing.Cell[i].pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } RTMP_IO_READ32(pAd, pAd->MgmtRing.hw_didx_addr, &pAd->MgmtRing.TxDmaIdx); pAd->MgmtRing.TxSwFreeIdx = pAd->MgmtRing.TxDmaIdx; pAd->MgmtRing.TxCpuIdx = pAd->MgmtRing.TxDmaIdx; RTMP_IO_WRITE32(pAd, pAd->MgmtRing.hw_cidx_addr, pAd->MgmtRing.TxCpuIdx); RTMP_IRQ_UNLOCK(&pAd->MgmtRingLock, IrqFlags); pAd->RalinkCounters.MgmtRingFullCount = 0; break; case QID_RX: for (ring_id =0; ring_id < NUM_OF_RX_RING; ring_id++) { RTMP_RX_RING *pRxRing; NDIS_SPIN_LOCK *lock; pRxRing = &pAd->RxRing[ring_id]; lock = &pAd->RxRingLock[ring_id]; RTMP_IRQ_LOCK(lock, IrqFlags); for (i=0; i<RX_RING_SIZE; i++) { #ifdef RT_BIG_ENDIAN pDestRxD = (RXD_STRUC *)pRxRing->Cell[i].AllocVa; RxD = *pDestRxD; pRxD = &RxD; RTMPDescriptorEndianChange((PUCHAR)pRxD, TYPE_RXD); #else /* Point to Rx indexed rx ring descriptor*/ pRxD = (RXD_STRUC *)pRxRing->Cell[i].AllocVa; #endif /* RT_BIG_ENDIAN */ pRxD->DDONE = 0; pRxD->SDL0 = RX_BUFFER_AGGRESIZE; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pRxD, TYPE_RXD); WriteBackToDescriptor((PUCHAR)pDestRxD, (PUCHAR)pRxD, FALSE, TYPE_RXD); #endif /* RT_BIG_ENDIAN */ } RTMP_IO_READ32(pAd, pRxRing->hw_didx_addr, &pRxRing->RxDmaIdx); pRxRing->RxSwReadIdx = pRxRing->RxDmaIdx; pRxRing->RxCpuIdx = ((pRxRing->RxDmaIdx == 0) ? (RX_RING_SIZE-1) : (pRxRing->RxDmaIdx-1)); RTMP_IO_WRITE32(pAd, pRxRing->hw_cidx_addr, pRxRing->RxCpuIdx); RTMP_IRQ_UNLOCK(lock, IrqFlags); } break; #ifdef CONFIG_ANDES_SUPPORT case QID_CTRL: RTMP_IRQ_LOCK(&pAd->CtrlRingLock, IrqFlags); for (i=0; i<MGMT_RING_SIZE; i++) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *) pAd->CtrlRing.Cell[i].AllocVa; TxD = *pDestTxD; pTxD = &TxD; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) pAd->CtrlRing.Cell[i].AllocVa; #endif /* RT_BIG_ENDIAN */ pPacket = (PNDIS_PACKET) pAd->CtrlRing.Cell[i].pNdisPacket; /* rlease scatter-and-gather NDIS_PACKET*/ if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->CtrlRing.Cell[i].pNdisPacket = NULL; pPacket = (PNDIS_PACKET) pAd->CtrlRing.Cell[i].pNextNdisPacket; /* release scatter-and-gather NDIS_PACKET*/ if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->CtrlRing.Cell[i].pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } RTMP_IO_READ32(pAd, pAd->CtrlRing.hw_didx_addr, &pAd->CtrlRing.TxDmaIdx); pAd->CtrlRing.TxSwFreeIdx = pAd->CtrlRing.TxDmaIdx; pAd->CtrlRing.TxCpuIdx = pAd->CtrlRing.TxDmaIdx; RTMP_IO_WRITE32(pAd, pAd->CtrlRing.hw_cidx_addr, pAd->CtrlRing.TxCpuIdx); RTMP_IRQ_UNLOCK(&pAd->CtrlRingLock, IrqFlags); break; #endif /* CONFIG_ANDES_SUPPORT */ #ifdef MT_MAC case QID_BCN: RTMP_IRQ_LOCK(&pAd->BcnRingLock, IrqFlags); for (i = 0; i < BCN_RING_SIZE; i++) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *)pAd->BcnRing.Cell[i].AllocVa; TxD = *pDestTxD; pTxD = &TxD; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) pAd->BcnRing.Cell[i].AllocVa; #endif /* RT_BIG_ENDIAN */ pPacket = (PNDIS_PACKET) pAd->BcnRing.Cell[i].pNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); //RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->BcnRing.Cell[i].pNdisPacket = NULL; pPacket = (PNDIS_PACKET) pAd->BcnRing.Cell[i].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); //RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->BcnRing.Cell[i].pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } RTMP_IO_READ32(pAd, pAd->BcnRing.hw_didx_addr, &pAd->BcnRing.TxDmaIdx); pAd->BcnRing.TxSwFreeIdx = pAd->BcnRing.TxDmaIdx; pAd->BcnRing.TxCpuIdx = pAd->BcnRing.TxDmaIdx; RTMP_IO_WRITE32(pAd, pAd->BcnRing.hw_cidx_addr, pAd->BcnRing.TxCpuIdx); RTMP_IRQ_UNLOCK(&pAd->BcnRingLock, IrqFlags); break; case QID_BMC: for (i = 0; i < TX_RING_SIZE; i++) { #ifdef RT_BIG_ENDIAN pDestTxD = (TXD_STRUC *)pAd->TxBmcRing.Cell[i].AllocVa; TxD = *pDestTxD; pTxD = &TxD; RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); #else pTxD = (TXD_STRUC *) pAd->TxBmcRing.Cell[i].AllocVa; #endif /* RT_BIG_ENDIAN */ pPacket = (PNDIS_PACKET) pAd->TxBmcRing.Cell[i].pNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->TxBmcRing.Cell[i].pNdisPacket = NULL; pPacket = (PNDIS_PACKET) pAd->TxBmcRing.Cell[i].pNextNdisPacket; if (pPacket) { PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, RTMP_PCI_DMA_TODEVICE); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } pAd->TxBmcRing.Cell[i].pNextNdisPacket = NULL; #ifdef RT_BIG_ENDIAN RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD); WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD); #endif /* RT_BIG_ENDIAN */ } RTMP_IO_READ32(pAd, pAd->TxBmcRing.hw_didx_addr, &pAd->TxBmcRing.TxDmaIdx); pAd->TxBmcRing.TxSwFreeIdx = pAd->TxBmcRing.TxDmaIdx; pAd->TxBmcRing.TxCpuIdx = pAd->TxBmcRing.TxDmaIdx; RTMP_IO_WRITE32(pAd, pAd->TxBmcRing.hw_cidx_addr, pAd->TxBmcRing.TxCpuIdx); break; #endif /* MT_MAC */ default: break; } } VOID PDMAResetAndRecovery(RTMP_ADAPTER *pAd) { UINT32 RemapBase, RemapOffset; UINT32 Value; UINT32 RestoreValue; UINT32 Loop = 0; ULONG IrqFlags = 0; /* Stop SW Dequeue */ RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_DISABLE_DEQUEUEPACKET); RTMP_ASIC_INTERRUPT_DISABLE(pAd); /* Disable PDMA */ RT28XXDMADisable(pAd); RtmpOsMsDelay(1); pAd->RxReset = 1; /* Assert csr_force_tx_eof */ RTMP_IO_READ32(pAd, MT_WPDMA_GLO_CFG , &Value); Value |= FORCE_TX_EOF; RTMP_IO_WRITE32(pAd, MT_WPDMA_GLO_CFG, Value); /* Infor PSE client of TX abort */ RTMP_IO_READ32(pAd, MCU_PCIE_REMAP_2, &RestoreValue); RemapBase = GET_REMAP_2_BASE(RST) << 19; RemapOffset = GET_REMAP_2_OFFSET(RST); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); Value |= TX_R_E_1; RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, Value); do { RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); if((Value & TX_R_E_1_S) == TX_R_E_1_S) break; RtmpOsMsDelay(1); Loop++; } while (Loop <= 500); if (Loop > 500) { DBGPRINT(RT_DEBUG_ERROR, ("%s: Tx state is not idle(CLIET RST = %x)\n", __FUNCTION__, Value)); pAd->PDMAResetFailCount++; } RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); Value |= TX_R_E_2; RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, Value); /* Reset PDMA */ RTMP_IO_READ32(pAd, MT_WPDMA_GLO_CFG , &Value); Value |= SW_RST; RTMP_IO_WRITE32(pAd, MT_WPDMA_GLO_CFG, Value); Loop = 0; /* Polling for PSE client to clear TX FIFO */ do { RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); if((Value & TX_R_E_2_S) == TX_R_E_2_S) break; RtmpOsMsDelay(1); Loop++; } while (Loop <= 500); if (Loop > 500) { DBGPRINT(RT_DEBUG_ERROR, ("%s: Tx FIFO is not empty(CLIET RST = %x)\n", __FUNCTION__, Value)); pAd->PDMAResetFailCount++; } /* De-assert PSE client TX abort */ RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); Value &= ~TX_R_E_1; Value &= ~TX_R_E_2; RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, Value); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RestoreValue); AsicDisableSync(pAd); RTMP_IRQ_LOCK(&pAd->BcnRingLock, IrqFlags); #ifdef CONFIG_AP_SUPPORT if (pAd->OpMode == OPMODE_AP) { UCHAR idx; for (idx = 0; idx < pAd->ApCfg.BssidNum; idx++) { BSS_STRUCT *pMbss; pMbss = &pAd->ApCfg.MBSSID[idx]; ASSERT(pMbss); if (pMbss) { pMbss->bcn_buf.bcn_state = BCN_TX_IDLE; } else { DBGPRINT(RT_DEBUG_ERROR, ("%s():func_dev is NULL!\n", __FUNCTION__)); RTMP_IRQ_UNLOCK(&pAd->BcnRingLock, IrqFlags); return ; } } } #endif RTMP_IRQ_UNLOCK(&pAd->BcnRingLock, IrqFlags); RTMPRingCleanUp(pAd, QID_AC_BE); RTMPRingCleanUp(pAd, QID_AC_BK); RTMPRingCleanUp(pAd, QID_AC_VI); RTMPRingCleanUp(pAd, QID_AC_VO); RTMPRingCleanUp(pAd, QID_MGMT); RTMPRingCleanUp(pAd, QID_CTRL); RTMPRingCleanUp(pAd, QID_BCN); RTMPRingCleanUp(pAd, QID_BMC); RTMPRingCleanUp(pAd, QID_RX); AsicEnableBssSync(pAd, pAd->CommonCfg.BeaconPeriod); /* Enable PDMA */ RT28XXDMAEnable(pAd); RTMP_ASIC_INTERRUPT_ENABLE(pAd); /* Enable SW Dequeue */ RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_DISABLE_DEQUEUEPACKET); } VOID PDMAWatchDog(RTMP_ADAPTER *pAd) { BOOLEAN NoDataOut = FALSE, NoDataIn = FALSE; /* Tx DMA unchaged detect */ NoDataOut = MonitorTxRing(pAd); if (NoDataOut) { DBGPRINT(RT_DEBUG_OFF, ("TXDMA Reset\n")); pAd->TxDMAResetCount++; goto reset; } /* Rx DMA unchanged detect */ NoDataIn = MonitorRxRing(pAd); if (NoDataIn) { DBGPRINT(RT_DEBUG_OFF, ("RXDMA Reset\n")); pAd->RxDMAResetCount++; goto reset; } return; reset: #ifdef DMA_RESET_SUPPORT //replace with PSE reset instead of PMDA reset. pAd->pse_reset_flag=TRUE; #else /* DMA_RESET_SUPPORT */ PDMAResetAndRecovery(pAd); #endif /* !DMA_RESET_SUPPORT */ } VOID DumpPseInfo(RTMP_ADAPTER *pAd) { UINT32 RemapBase, RemapOffset; UINT32 Value; UINT32 RestoreValue; UINT32 Index; RTMP_IO_READ32(pAd, MCU_PCIE_REMAP_2, &RestoreValue); /* PSE Infomation */ for (Index = 0; Index < 30720; Index++) { RemapBase = GET_REMAP_2_BASE(0xa5000000 + Index * 4) << 19; RemapOffset = GET_REMAP_2_OFFSET(0xa5000000 + Index * 4); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_OFF, ("Offset[0x%x] = 0x%x\n", 0xa5000000 + Index * 4, Value)); } /* Frame linker */ for (Index = 0; Index < 1280; Index++) { RemapBase = GET_REMAP_2_BASE(0xa00001b0) << 19; RemapOffset = GET_REMAP_2_OFFSET(0xa00001b0); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); Value &= ~0xfff; Value |= (Index & 0xfff); RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, Value); RemapBase = GET_REMAP_2_BASE(0xa00001b4) << 19; RemapOffset = GET_REMAP_2_OFFSET(0xa00001b4); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_OFF, ("Frame Linker(0x%x) = 0x%x\n", Index, Value )); } /* Page linker */ for (Index = 0; Index < 1280; Index++) { RemapBase = GET_REMAP_2_BASE(0xa00001b8) << 19; RemapOffset = GET_REMAP_2_OFFSET(0xa00001b8); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); Value &= ~(0xfff << 16); Value |= ((Index & 0xfff) << 16); RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, Value); RemapBase = GET_REMAP_2_BASE(0xa00001b8) << 19; RemapOffset = GET_REMAP_2_OFFSET(0xa00001b8); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_OFF, ("Page Linker(0x%x) = 0x%x\n", Index, (Value & 0xfff))); } RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RestoreValue); } VOID PSEResetAndRecovery(RTMP_ADAPTER *pAd) { UINT32 Loop = 0; UINT32 Value; #ifdef RTMP_PCI_SUPPORT NdisAcquireSpinLock(&pAd->IndirectUpdateLock); #endif RTMP_IO_READ32(pAd, 0x816c, &Value); if((Value & (1 << 1)) == (1 << 1)) { Value &= ~(1 << 1); DBGPRINT(RT_DEBUG_ERROR, ("@@@ %s: This Reset Result may be old! force clean result first! \n", __FUNCTION__)); RTMP_IO_WRITE32(pAd, 0x816c, Value); } RTMP_IO_READ32(pAd, 0x816c, &Value); Value |= (1 << 0); RTMP_IO_WRITE32(pAd, 0x816c, Value); do { RTMP_IO_READ32(pAd, 0x816c, &Value); if((Value & (1 << 1)) == (1 << 1)) { Value &= ~(1 << 1); RTMP_IO_WRITE32(pAd, 0x816c, Value); break; } RtmpOsMsDelay(1); Loop++; } while (Loop <= 500); if (Loop > 500) { DBGPRINT(RT_DEBUG_ERROR, ("%s: PSE Reset Fail(%x)\n", __FUNCTION__, Value)); #ifdef RTMP_PCI_SUPPORT /*Dump the PSE CRs*/ { UINT32 RemapBase, RemapOffset; UINT32 Value; UINT32 RestoreValue; { DBGPRINT(RT_DEBUG_ERROR, ("%s: START ============== PSE CR dump ===================\n", __FUNCTION__)); RTMP_IO_READ32(pAd, 0x816c, &Value); DBGPRINT(RT_DEBUG_ERROR, ("mac [0x816c] = 0x%08x\n", Value)); RTMP_IO_READ32(pAd, 0x8170, &Value); DBGPRINT(RT_DEBUG_ERROR, ("mac [0x8170] = 0x%08x\n", Value)); RTMP_IO_READ32(pAd, MCU_PCIE_REMAP_2, &RestoreValue); RemapBase = GET_REMAP_2_BASE(0x800c0070) << 19; RemapOffset = GET_REMAP_2_OFFSET(0x800c0070); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 3 : mac [0x800c0070] = 0x%08x\n", Value)); //RTMP_IO_READ32(pAd, MCU_PCIE_REMAP_2, &RestoreValue); RemapBase = GET_REMAP_2_BASE(0x800c006c) << 19; RemapOffset = GET_REMAP_2_OFFSET(0x800c006c); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RemapBase); // write 3 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 3); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 3 : mac [0x800c006c] = 0x%08x\n", Value)); // write 4 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 4); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 4 : mac [0x800c006c] = 0x%08x\n", Value)); // write 5 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 5); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 5 : mac [0x800c006c] = 0x%08x\n", Value)); // write 6 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 6); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 6 :mac [0x800c006c] = 0x%08x\n", Value)); // write 7 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 7); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 7 :mac [0x800c006c] = 0x%08x\n", Value)); // write 8 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 8); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 8 :mac [0x800c006c] = 0x%08x\n", Value)); // write 9 RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 9); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw 9 :mac [0x800c006c] = 0x%08x\n", Value)); // write a RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 0xa); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw a :mac [0x800c006c] = 0x%08x\n", Value)); // write b RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 0xb); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw b :mac [0x800c006c] = 0x%08x\n", Value)); // write c RTMP_IO_WRITE32(pAd, 0x80000 + RemapOffset, 0xc); RTMP_IO_READ32(pAd, 0x80000 + RemapOffset, &Value); DBGPRINT(RT_DEBUG_ERROR, ("rw c :mac [0x800c006c] = 0x%08x\n", Value)); RTMP_IO_WRITE32(pAd, MCU_PCIE_REMAP_2, RestoreValue); DBGPRINT(RT_DEBUG_ERROR, ("%s: END ============== PSE CR dump ===================\n", __FUNCTION__)); } } #endif /* RTMP_PCI_SUPPORT */ #ifdef DMA_RESET_SUPPORT RTMP_IO_READ32(pAd, 0x816c, &Value); if ((Value & (1 << 0)) == (1 << 0)) { DBGPRINT(RT_DEBUG_ERROR, ("@@@ %s: Host Poll Fail !! Try to abort this PSE reset to F/W!! \n", __FUNCTION__)); Value &= ~(1 << 0); RTMP_IO_WRITE32(pAd, 0x816c, Value); } if (pAd->PSEResetFailRecover == FALSE) { pAd->PSEResetFailRecover = TRUE; pAd->PSEResetFailRetryQuota = 3; // start to count down } else { if (pAd->PSEResetFailRetryQuota) pAd->PSEResetFailRetryQuota --; if (pAd->PSEResetFailRetryQuota == 0) // reach the quota { pAd->PSEResetFailRecover = FALSE; DBGPRINT(RT_DEBUG_ERROR, ("%s: PSE Reset Retry Reach Quota!!\n", __FUNCTION__)); } } #endif /* DMA_RESET_SUPPORT */ pAd->PSEResetFailCount++; #ifdef RTMP_PCI_SUPPORT NdisReleaseSpinLock(&pAd->IndirectUpdateLock); #endif return; } #ifdef DMA_RESET_SUPPORT else //Reset Success { if (pAd->PSEResetFailRecover) { DBGPRINT(RT_DEBUG_ERROR, ("%s: PSE Reset Recover Back!!\n", __FUNCTION__)); } pAd->PSEResetFailRecover = FALSE; pAd->PSEResetFailRetryQuota = 0; } //clear the AC / Mgmt Hit event. RTMP_IO_READ32(pAd, 0x816c, &Value); if((Value & (1 << 2)) == (1 << 2)) { Value &= ~(1 << 2); RTMP_IO_WRITE32(pAd, 0x816c, Value); } if((Value & (1 << 3)) == (1 << 3)) { Value &= ~(1 << 3); RTMP_IO_WRITE32(pAd, 0x816c, Value); } if((Value & (1 << 4)) == (1 << 4)) { Value &= ~(1 << 4); RTMP_IO_WRITE32(pAd, 0x816c, Value); } if((Value & (1 << 5)) == (1 << 5)) { Value &= ~(1 << 5); RTMP_IO_WRITE32(pAd, 0x816c, Value); } if((Value & (1 << 6)) == (1 << 6)) { Value &= ~(1 << 6); RTMP_IO_WRITE32(pAd, 0x816c, Value); } #endif /* DMA_RESET_SUPPORT */ #ifdef RTMP_PCI_SUPPORT NdisReleaseSpinLock(&pAd->IndirectUpdateLock); #endif PDMAResetAndRecovery(pAd); } #ifdef DMA_RESET_SUPPORT VOID PSEACStuckWatchDog(RTMP_ADAPTER *pAd) { UINT32 Value; RTMP_IO_READ32(pAd, 0x816c, &Value); //AC if((Value & (1 << 2)) == (1 << 2)) { //clear after reset //Value &= ~(1 << 2); //RTMP_IO_WRITE32(pAd, 0x816c, Value); if ( #ifdef MAX_CONTINOUS_TX_CNT pAd->ContinousTxCnt != 1 || #endif pAd->ed_on == TRUE) { pAd->pse_reset_flag = FALSE; Value &= ~(1 << 2); RTMP_IO_WRITE32(pAd, 0x816c, Value); DBGPRINT(RT_DEBUG_OFF, ("Ignore HIT AC0 ! pAd->ed_on = %d\n", pAd->ed_on)); #ifdef MAX_CONTINOUS_TX_CNT DBGPRINT(RT_DEBUG_OFF, ("pAd->ContinousTxCnt = %d\n", pAd->ContinousTxCnt)); #endif } else { DBGPRINT(RT_DEBUG_OFF, ("HIT AC0 !\n")); pAd->AC0HitCount++; pAd->pse_reset_flag = TRUE; } } if((Value & (1 << 3)) == (1 << 3)) { //clear after reset //Value &= ~(1 << 3); //RTMP_IO_WRITE32(pAd, 0x816c, Value); if ( #ifdef MAX_CONTINOUS_TX_CNT pAd->ContinousTxCnt != 1 || #endif pAd->ed_on == TRUE) { pAd->pse_reset_flag = FALSE; Value &= ~(1 << 3); RTMP_IO_WRITE32(pAd, 0x816c, Value); DBGPRINT(RT_DEBUG_OFF, ("Ignore HIT AC1 ! pAd->ed_on = %d\n", pAd->ed_on)); #ifdef MAX_CONTINOUS_TX_CNT DBGPRINT(RT_DEBUG_OFF, ("pAd->ContinousTxCnt = %d\n", pAd->ContinousTxCnt)); #endif } else { DBGPRINT(RT_DEBUG_OFF, ("HIT AC1 !\n")); pAd->AC1HitCount++; pAd->pse_reset_flag = TRUE; } } if((Value & (1 << 4)) == (1 << 4)) { //clear after reset //Value &= ~(1 << 4); //RTMP_IO_WRITE32(pAd, 0x816c, Value); if ( #ifdef MAX_CONTINOUS_TX_CNT pAd->ContinousTxCnt != 1 || #endif pAd->ed_on == TRUE) { pAd->pse_reset_flag = FALSE; Value &= ~(1 << 4); RTMP_IO_WRITE32(pAd, 0x816c, Value); DBGPRINT(RT_DEBUG_OFF, ("Ignore HIT AC2 ! pAd->ed_on = %d\n", pAd->ed_on)); #ifdef MAX_CONTINOUS_TX_CNT DBGPRINT(RT_DEBUG_OFF, ("pAd->ContinousTxCnt = %d\n", pAd->ContinousTxCnt)); #endif } else { DBGPRINT(RT_DEBUG_OFF, ("HIT AC2 !\n")); pAd->AC2HitCount++; pAd->pse_reset_flag = TRUE; } } if((Value & (1 << 5)) == (1 << 5)) { //clear after reset //Value &= ~(1 << 5); //RTMP_IO_WRITE32(pAd, 0x816c, Value); if ( #ifdef MAX_CONTINOUS_TX_CNT pAd->ContinousTxCnt != 1 || #endif pAd->ed_on == TRUE) { pAd->pse_reset_flag = FALSE; Value &= ~(1 << 5); RTMP_IO_WRITE32(pAd, 0x816c, Value); DBGPRINT(RT_DEBUG_OFF, ("Ignore HIT AC3 ! pAd->ed_on = %d\n", pAd->ed_on)); #ifdef MAX_CONTINOUS_TX_CNT DBGPRINT(RT_DEBUG_OFF, ("pAd->ContinousTxCnt = %d\n", pAd->ContinousTxCnt)); #endif } else { DBGPRINT(RT_DEBUG_OFF, ("HIT AC3 !\n")); pAd->AC3HitCount++; pAd->pse_reset_flag = TRUE; } //return TRUE; } if((Value & (1 << 6)) == (1 << 6)) { //clear after reset //Value &= ~(1 << 6); //RTMP_IO_WRITE32(pAd, 0x816c, Value); if (RTDebugLevel >= RT_DEBUG_OFF) printk("HIT MGMT !\n"); pAd->MgtHitCount ++; pAd->pse_reset_flag = TRUE; //return TRUE; } } #endif /* DMA_RESET_SUPPORT */ VOID PSEWatchDog(RTMP_ADAPTER *pAd) { BOOLEAN NoDataIn = FALSE; NoDataIn = MonitorRxPse(pAd); if (((NoDataIn) #ifdef DMA_RESET_SUPPORT || ((pAd->bcn_reset_en) && (pAd->pse_reset_flag)) || ((pAd->PSEResetFailRecover) && (pAd->PSEResetFailRetryQuota)) #endif ) && (pAd->pse_reset_exclude_flag == FALSE)) { DBGPRINT(RT_DEBUG_OFF, ("PSE Reset: MonitorRxPse\n")); DBGPRINT(RT_DEBUG_OFF, ("NoDataIn = %d, bcn_reset_en = %d, pse_reset_flag = %d\n", NoDataIn, pAd->bcn_reset_en, pAd->pse_reset_flag)); DBGPRINT(RT_DEBUG_OFF, ("PSEResetFailRecover = %d, PSEResetFailRetryQuota = %ld\n", pAd->PSEResetFailRecover, pAd->PSEResetFailRetryQuota)); pAd->PSEResetCount++; goto reset; } /*MT7628's case may not apply to MT7603 */ return; reset: #ifdef DMA_RESET_SUPPORT pAd->pse_reset_flag=TRUE; #endif pAd->pse_reset_exclude_flag = TRUE; PSEResetAndRecovery(pAd); pAd->pse_reset_exclude_flag = FALSE; #ifdef DMA_RESET_SUPPORT pAd->pse_reset_flag=FALSE; #endif } /*************************************************************************** * * register related procedures. * **************************************************************************/ /* ======================================================================== Routine Description: Disable DMA. Arguments: *pAd the raxx interface data pointer Return Value: None Note: ======================================================================== */ VOID RT28XXDMADisable(RTMP_ADAPTER *pAd) { AsicSetWPDMA(pAd, PDMA_TX_RX, FALSE); } /* ======================================================================== Routine Description: Enable DMA. Arguments: *pAd the raxx interface data pointer Return Value: None Note: ======================================================================== */ VOID RT28XXDMAEnable(RTMP_ADAPTER *pAd) { AsicSetMacTxRx(pAd, ASIC_MAC_TX, TRUE); AsicWaitPDMAIdle(pAd, 200, 1000); RtmpusecDelay(50); AsicSetWPDMA(pAd, PDMA_TX_RX, TRUE); DBGPRINT(RT_DEBUG_TRACE, ("<== %s(): WPDMABurstSIZE = %d\n", __FUNCTION__, pAd->chipCap.WPDMABurstSIZE)); } BOOLEAN AsicCheckCommanOk(RTMP_ADAPTER *pAd, UCHAR Command) { BOOLEAN status = FALSE; // TODO: shiang-7603 if (pAd->chipCap.hif_type == HIF_MT) { DBGPRINT(RT_DEBUG_OFF, ("%s(%d): Not support for HIF_MT yet!\n", __FUNCTION__, __LINE__)); return TRUE; } return status; } #ifdef MT_MAC VOID RT28xx_UpdateBeaconToAsic( IN RTMP_ADAPTER *pAd, IN INT apidx, IN ULONG FrameLen, IN ULONG UpdatePos) { BCN_BUF_STRUC *bcn_buf = NULL; UCHAR *buf/*, *hdr*/; INT len; PNDIS_PACKET *pkt = NULL; #ifdef CONFIG_AP_SUPPORT IF_DEV_CONFIG_OPMODE_ON_AP(pAd) { bcn_buf = &pAd->ApCfg.MBSSID[apidx].bcn_buf; } #endif /* CONFIG_AP_SUPPORT */ if (!bcn_buf) { DBGPRINT(RT_DEBUG_ERROR, ("%s(): bcn_buf is NULL!\n", __FUNCTION__)); return; } pkt = bcn_buf->BeaconPkt; if (pkt) { buf = (UCHAR *)GET_OS_PKT_DATAPTR(pkt); len = FrameLen + pAd->chipCap.tx_hw_hdr_len; SET_OS_PKT_LEN(pkt, len); #ifdef RT_BIG_ENDIAN MTMacInfoEndianChange(pAd, buf, TYPE_TMACINFO, sizeof(TMAC_TXD_L)); #endif /* RT_BIG_ENDIAN */ /* Now do hardware-depened kick out.*/ RTMP_SEM_LOCK(&pAd->BcnRingLock); HAL_KickOutMgmtTx(pAd, Q_IDX_BCN, pkt, buf, len); bcn_buf->bcn_state = BCN_TX_WRITE_TO_DMA; RTMP_SEM_UNLOCK(&pAd->BcnRingLock); } else { DBGPRINT(RT_DEBUG_ERROR, ("%s(): BeaconPkt is NULL!\n", __FUNCTION__)); } } #endif /* MT_MAC */ #if defined(RTMP_MAC) || defined(RLT_MAC) /* ======================================================================== Routine Description: Write Beacon buffer to Asic. Arguments: *pAd the raxx interface data pointer Return Value: None Note: ======================================================================== */ VOID RT28xx_UpdateBeaconToAsic( IN RTMP_ADAPTER *pAd, IN INT apidx, IN ULONG FrameLen, IN ULONG UpdatePos) { ULONG CapInfoPos = 0; UCHAR *ptr, *ptr_update, *ptr_capinfo; UINT i; BOOLEAN bBcnReq = FALSE; UCHAR bcn_idx = 0; UINT8 TXWISize = pAd->chipCap.TXWISize; INT wr_bytes = 1; UCHAR *pBeaconFrame, *tmac_info; UCHAR tx_hw_hdr_len = pAd->chipCap.tx_hw_hdr_len; if (IS_MT76x2(pAd)) wr_bytes = 4; #ifdef CONFIG_AP_SUPPORT if (apidx < pAd->ApCfg.BssidNum && apidx < HW_BEACON_MAX_NUM && (pAd->OpMode == OPMODE_AP) ) { BSS_STRUCT *pMbss; pMbss = &pAd->ApCfg.MBSSID[apidx]; bcn_idx = pMbss->bcn_buf.BcnBufIdx; CapInfoPos = pMbss->bcn_buf.cap_ie_pos; bBcnReq = BeaconTransmitRequired(pAd, apidx, pMbss); if (wr_bytes > 1) { CapInfoPos = (CapInfoPos & (~(wr_bytes - 1))); UpdatePos = (UpdatePos & (~(wr_bytes - 1))); } tmac_info = (UCHAR *)GET_OS_PKT_DATAPTR(pMbss->bcn_buf.BeaconPkt); pBeaconFrame = (UCHAR *)(tmac_info + TXWISize); ptr_capinfo = (PUCHAR)(pBeaconFrame + CapInfoPos); ptr_update = (PUCHAR)(pBeaconFrame + UpdatePos); } else #endif /* CONFIG_AP_SUPPORT */ { DBGPRINT(RT_DEBUG_ERROR, ("%s():Invalid Interface\n", __FUNCTION__)); return; } if (pAd->BeaconOffset[bcn_idx] == 0) { DBGPRINT(RT_DEBUG_ERROR, ("%s():Invalid BcnOffset[%d]\n", __FUNCTION__, bcn_idx)); return; } if (bBcnReq == FALSE) { /* when the ra interface is down, do not send its beacon frame */ /* clear all zero */ for(i=0; i < TXWISize; i+=4) RTMP_CHIP_UPDATE_BEACON(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00, 4); } else { ptr = tmac_info; #ifdef RT_BIG_ENDIAN RTMPWIEndianChange(pAd, ptr, TYPE_TXWI); #endif for (i=0; i < TXWISize; i+=4) /* 16-byte TXWI field*/ { UINT32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); RTMP_CHIP_UPDATE_BEACON(pAd, pAd->BeaconOffset[bcn_idx] + i, longptr, 4); ptr += 4; } /* Update CapabilityInfo in Beacon*/ for (i = CapInfoPos; i < (CapInfoPos+2); i += wr_bytes) { RTMP_CHIP_UPDATE_BEACON(pAd, pAd->BeaconOffset[bcn_idx] + TXWISize + i, *((UINT32 *)ptr_capinfo), wr_bytes); ptr_capinfo += wr_bytes; } if (FrameLen > UpdatePos) { for (i = UpdatePos; i < (FrameLen); i += wr_bytes) { UINT32 longptr = *ptr_update + (*(ptr_update+1)<<8) + (*(ptr_update+2)<<16) + (*(ptr_update+3)<<24); RTMP_CHIP_UPDATE_BEACON(pAd, pAd->BeaconOffset[bcn_idx] + TXWISize + i, longptr, wr_bytes); ptr_update += wr_bytes; } } } } #endif /* defined(RTMP_MAC) || defined(RLT_MAC) */ /* ========================================================================== Description: This routine sends command to firmware and turn our chip to wake up mode from power save mode. Both RadioOn and .11 power save function needs to call this routine. Input: Level = GUIRADIO_OFF : call this function is from Radio Off to Radio On. Need to restore PCI host value. Level = other value : normal wake up function. ========================================================================== */ BOOLEAN RT28xxPciAsicRadioOn(RTMP_ADAPTER *pAd, UCHAR Level) { if (pAd->OpMode == OPMODE_AP && Level==DOT11POWERSAVE) return FALSE; /* 2. Send wake up command.*/ AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, 0x02, FALSE); pAd->bPCIclkOff = FALSE; /* 2-1. wait command ok.*/ AsicCheckCommanOk(pAd, PowerWakeCID); RTMP_ASIC_INTERRUPT_ENABLE(pAd); RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); if (Level == GUI_IDLE_POWER_SAVE) { /*2009/06/09: AP and stations need call the following function*/ /* add by johnli, RF power sequence setup, load RF normal operation-mode setup*/ RTMP_CHIP_OP *pChipOps = &pAd->chipOps; if (pChipOps->AsicReverseRfFromSleepMode) { pChipOps->AsicReverseRfFromSleepMode(pAd, FALSE); } else { /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again.*/ #ifdef CONFIG_AP_SUPPORT IF_DEV_CONFIG_OPMODE_ON_AP(pAd) { AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); } #endif /* CONFIG_AP_SUPPORT */ } } return TRUE; } /* ========================================================================== Description: This routine sends command to firmware and turn our chip to power save mode. Both RadioOff and .11 power save function needs to call this routine. Input: Level = GUIRADIO_OFF : GUI Radio Off mode Level = DOT11POWERSAVE : 802.11 power save mode Level = RTMP_HALT : When Disable device. ========================================================================== */ BOOLEAN RT28xxPciAsicRadioOff( IN RTMP_ADAPTER *pAd, IN UCHAR Level, IN USHORT TbttNumToNextWakeUp) { #if defined(RTMP_MAC) || defined(RLT_MAC) UINT32 RxDmaIdx, RxCpuIdx; #endif /* defined(RTMP_MAC) || defined(RLT_MAC) */ // TODO: shiang-7603 if (pAd->chipCap.hif_type == HIF_MT) { DBGPRINT(RT_DEBUG_OFF, ("%s(): Not support for HIF_MT yet!\n", __FUNCTION__)); return FALSE; } #if defined(RTMP_MAC) || defined(RLT_MAC) DBGPRINT(RT_DEBUG_TRACE, ("%s ===> Lv= %d, TxCpuIdx = %d, TxDmaIdx = %d. RxCpuIdx = %d, RxDmaIdx = %d.\n", __FUNCTION__, Level,pAd->TxRing[0].TxCpuIdx, pAd->TxRing[0].TxDmaIdx, pAd->RxRing[0].RxCpuIdx, pAd->RxRing[0].RxDmaIdx)); if (pAd->OpMode == OPMODE_AP && Level==DOT11POWERSAVE) return FALSE; if (Level == DOT11POWERSAVE) { /* Check Rx DMA busy status, if more than half is occupied, give up this radio off.*/ RTMP_IO_READ32(pAd, pAd->RxRing[0].hw_didx_addr, &RxDmaIdx); RTMP_IO_READ32(pAd, pAd->RxRing[0].hw_cidx_addr, &RxCpuIdx); if ((RxDmaIdx > RxCpuIdx) && ((RxDmaIdx - RxCpuIdx) > RX_RING_SIZE/3)) { DBGPRINT(RT_DEBUG_TRACE, ("%s(): return1. RxDmaIdx=%d, RxCpuIdx=%d\n", __FUNCTION__, RxDmaIdx, RxCpuIdx)); return FALSE; } else if ((RxCpuIdx >= RxDmaIdx) && ((RxCpuIdx - RxDmaIdx) < RX_RING_SIZE/3)) { DBGPRINT(RT_DEBUG_TRACE, ("%s(): return2. RxDmaIdx=%d, RxCpuIdx=%d\n", __FUNCTION__, RxDmaIdx, RxCpuIdx)); return FALSE; } } /* Once go into this function, disable tx because don't want too many packets in queue to prevent HW stops.*/ /*pAd->bPCIclkOffDisableTx = TRUE;*/ /*pAd->bPCIclkOffDisableTx = FALSE;*/ RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again.*/ AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel); if (Level != RTMP_HALT) { UINT32 AutoWakeupInt = 0; #ifdef RLT_MAC if (pAd->chipCap.hif_type == HIF_RLT) AutoWakeupInt = RLT_AutoWakeupInt; #endif /* RLT_MAC*/ #ifdef RTMP_MAC if (pAd->chipCap.hif_type == HIF_RTMP) AutoWakeupInt = RTMP_AutoWakeupInt; #endif /* RTMP_MAC */ /* Change Interrupt bitmask. When PCI clock is off, don't want to service interrupt. */ RTMP_IO_WRITE32(pAd, INT_MASK_CSR, AutoWakeupInt); } else { if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) RTMP_ASIC_INTERRUPT_DISABLE(pAd); } RTMP_IO_WRITE32(pAd, pAd->RxRing[0].hw_cidx_addr, pAd->RxRing[0].RxCpuIdx); /* 2. Send Sleep command */ RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff); RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff); /* send POWER-SAVE command to MCU. high-byte = 1 save power as much as possible. high byte = 0 save less power*/ AsicSendCommandToMcu(pAd, SLEEP_MCU_CMD, PowerSafeCID, 0xff, 0x1, FALSE); /* Disable for stability. If PCIE Link Control is modified for advance power save, re-covery this code segment.*/ /*RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x1280);*/ /*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_CLKSELECT_40MHZ);*/ if (Level == DOT11POWERSAVE) { AUTO_WAKEUP_STRUC AutoWakeupCfg; /*RTMPSetTimer(&pAd->Mlme.PsPollTimer, 90);*/ /* we have decided to SLEEP, so at least do it for a BEACON period.*/ if (TbttNumToNextWakeUp == 0) TbttNumToNextWakeUp = 1; AutoWakeupCfg.word = 0; RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); /* 1. Set auto wake up timer.*/ AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1; AutoWakeupCfg.field.EnableAutoWakeup = 1; AutoWakeupCfg.field.AutoLeadTime = LEAD_TIME; RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); } /*pAd->bPCIclkOffDisableTx = FALSE;*/ #endif /* defined(RTMP_MAC) || defined(RLT_MAC) */ return TRUE; } VOID PciMlmeRadioOn(RTMP_ADAPTER *pAd) { #ifdef LOAD_FW_ONE_TIME { UINT32 value; RTMP_IO_READ32(pAd, AGG_TEMP, &value); value &= 0x0000ffff; RTMP_IO_WRITE32(pAd, AGG_TEMP, value); } #endif /* LOAD_FW_ONE_TIME */ if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) return; DBGPRINT(RT_DEBUG_TRACE,("%s===>\n", __FUNCTION__)); #ifdef MT_MAC if (pAd->chipCap.hif_type == HIF_MT) { MTPciMlmeRadioOn(pAd); return; } #endif /* MT_MAC */ #if defined(RTMP_MAC) || defined(RLT_MAC) if ((pAd->OpMode == OPMODE_AP) || ((pAd->OpMode == OPMODE_STA) )) { RTMPRingCleanUp(pAd, QID_AC_BK); RTMPRingCleanUp(pAd, QID_AC_BE); RTMPRingCleanUp(pAd, QID_AC_VI); RTMPRingCleanUp(pAd, QID_AC_VO); RTMPRingCleanUp(pAd, QID_HCCA); RTMPRingCleanUp(pAd, QID_MGMT); RTMPRingCleanUp(pAd, QID_RX); #ifdef RTMP_PCI_SUPPORT { if (pAd->infType == RTMP_DEV_INF_PCI || pAd->infType == RTMP_DEV_INF_PCIE) RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE); } #endif /* RTMP_PCI_SUPPORT */ /* Enable Tx/Rx*/ RTMPEnableRxTx(pAd); /* Clear Radio off flag*/ RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); #ifdef LED_CONTROL_SUPPORT RTMPSetLED(pAd, LED_RADIO_ON); #ifdef CONFIG_AP_SUPPORT /* The LEN_RADIO_ON indicates "Radio on but link down", so AP shall set LED LINK_UP status */ IF_DEV_CONFIG_OPMODE_ON_AP(pAd) { RTMPSetLED(pAd, LED_LINK_UP); } #endif /* CONFIG_AP_SUPPORT */ #endif /* LED_CONTROL_SUPPORT */ } #endif /* defined(RTMP_MAC) || defined(RLT_MAC) */ } VOID PciMlmeRadioOFF(RTMP_ADAPTER *pAd) { if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) return; DBGPRINT(RT_DEBUG_TRACE,("%s===>\n", __FUNCTION__)); #ifdef MT_MAC if (pAd->chipCap.hif_type == HIF_MT) { MTPciMlmeRadioOff(pAd); return; } #endif /* MT_MAC */ #if defined(RTMP_MAC) || defined(RLT_MAC) /* Set Radio off flag*/ RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); #ifdef CONFIG_AP_SUPPORT #ifdef AP_SCAN_SUPPORT { BOOLEAN Cancelled; RTMPCancelTimer(&pAd->ScanCtrl.APScanTimer, &Cancelled); } #endif /* AP_SCAN_SUPPORT */ #endif /* CONFIG_AP_SUPPORT */ #ifdef LED_CONTROL_SUPPORT RTMPSetLED(pAd, LED_RADIO_OFF); #endif /* LED_CONTROL_SUPPORT */ #ifdef RTMP_PCI_SUPPORT if (pAd->infType == RTMP_DEV_INF_PCI || pAd->infType == RTMP_DEV_INF_PCIE) { { if (RT28xxPciAsicRadioOff(pAd, GUIRADIO_OFF, 0) ==FALSE) { DBGPRINT(RT_DEBUG_ERROR,("%s call RT28xxPciAsicRadioOff fail !!\n", __FUNCTION__)); } } } #endif /* RTMP_PCI_SUPPORT */ #endif /* defined(RTMP_MAC) || defined(RLT_MAC) */ } /* ======================================================================== Routine Description: Get a pci map buffer. Arguments: pAd - WLAN control block pointer *ptr - Virtual address or TX control block size - buffer size sd_idx - 1: the ptr is TX control block direction - RTMP_PCI_DMA_TODEVICE or RTMP_PCI_DMA_FROMDEVICE Return Value: the PCI map buffer Note: ======================================================================== */ ra_dma_addr_t RtmpDrvPciMapSingle( IN RTMP_ADAPTER *pAd, IN VOID *ptr, IN size_t size, IN INT sd_idx, IN INT direction) { ra_dma_addr_t SrcBufPA; if (sd_idx == 1) { TX_BLK *pTxBlk = (TX_BLK *)(ptr); if (pTxBlk->SrcBufLen) { SrcBufPA = linux_pci_map_single(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev,pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, 0, direction); } else { return 0; } } else { SrcBufPA = linux_pci_map_single(((POS_COOKIE)(pAd->OS_Cookie))->pci_dev, ptr, size, 0, direction); } if (dma_mapping_error(&((POS_COOKIE)(pAd->OS_Cookie))->pci_dev->dev, SrcBufPA)) { DBGPRINT(RT_DEBUG_OFF, ("%s: dma mapping error\n", __FUNCTION__)); return 0; } else { return SrcBufPA; } } int write_reg(RTMP_ADAPTER *ad, UINT32 base, UINT16 offset, UINT32 value) { // TODO: shiang-7603 if (ad->chipCap.hif_type == HIF_MT) { DBGPRINT(RT_DEBUG_OFF, ("%s(): Not support for HIF_MT yet!\n", __FUNCTION__)); return FALSE; } if (base == 0x40) RTMP_IO_WRITE32(ad, 0x10000 + offset, value); else if (base == 0x41) RTMP_IO_WRITE32(ad, offset, value); else DBGPRINT(RT_DEBUG_OFF, ("illegal base = %x\n", base)); return 0; } int read_reg(RTMP_ADAPTER *ad, UINT32 base, UINT16 offset, UINT32 *value) { // TODO: shiang-7603 if (ad->chipCap.hif_type == HIF_MT) { DBGPRINT(RT_DEBUG_OFF, ("%s(): Not support for HIF_MT yet!\n", __FUNCTION__)); return FALSE; } if (base == 0x40) { RTMP_IO_READ32(ad, 0x10000 + offset, value); } else if (base == 0x41) { RTMP_IO_READ32(ad, offset, value); } else { DBGPRINT(RT_DEBUG_OFF, ("illegal base = %x\n", base)); } return 0; } INT rtmp_irq_init(RTMP_ADAPTER *pAd) { unsigned long irqFlags; UINT32 reg_mask = 0; #ifdef RLT_MAC if (pAd->chipCap.hif_type == HIF_RLT) reg_mask = (RLT_DELAYINTMASK) |(RLT_RxINT|RLT_TxDataInt|RLT_TxMgmtInt); #endif /* RLT_MAC */ #ifdef RTMP_MAC if (pAd->chipCap.hif_type == HIF_RTMP) reg_mask = ((RTMP_DELAYINTMASK) |(RTMP_RxINT|RTMP_TxDataInt|RTMP_TxMgmtInt)) & ~(0x03); #endif /* RTMP_MAC */ #ifdef MT_MAC // TODO: shiang-7603 if (pAd->chipCap.hif_type == HIF_MT) reg_mask = ((MT_DELAYINTMASK) |(MT_RxINT|MT_TxDataInt|MT_TxMgmtInt)|MT_INT_BMC_DLY); #endif /* MT_MAC */ RTMP_INT_LOCK(&pAd->irq_lock, irqFlags); pAd->int_enable_reg = reg_mask; pAd->int_disable_mask = 0; pAd->int_pending = 0; RTMP_INT_UNLOCK(&pAd->irq_lock, irqFlags); return 0; } #endif /* RTMP_MAC_PCI */
the_stack_data/218893267.c
/* Taxonomy Classification: 0000000100000021000010 */ /* * WRITE/READ 0 write * WHICH BOUND 0 upper * DATA TYPE 0 char * MEMORY LOCATION 0 stack * SCOPE 0 same * CONTAINER 0 no * POINTER 0 no * INDEX COMPLEXITY 1 variable * ADDRESS COMPLEXITY 0 constant * LENGTH COMPLEXITY 0 N/A * ADDRESS ALIAS 0 none * INDEX ALIAS 0 none * LOCAL CONTROL FLOW 0 none * SECONDARY CONTROL FLOW 0 none * LOOP STRUCTURE 2 do-while * LOOP COMPLEXITY 1 zero * ASYNCHRONY 0 no * TAINT 0 no * RUNTIME ENV. DEPENDENCE 0 no * MAGNITUDE 0 no overflow * CONTINUOUS/DISCRETE 1 continuous * SIGNEDNESS 0 no */ /* Copyright 2005 Massachusetts Institute of Technology All rights reserved. Redistribution and use of software 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 set of conditions and the disclaimer below. - Redistributions in binary form must reproduce the copyright notice, this set of conditions, and the disclaimer below in the documentation and/or other materials provided with the distribution. - Neither the name of the Massachusetts Institute of Technology 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS". 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. */ int main(int argc, char *argv[]) { int loop_counter; char buf[10]; loop_counter = 0; do { /* OK */ buf[loop_counter] = 'A'; loop_counter++; } while(loop_counter <= 9); return 0; }
the_stack_data/72073.c
/* Copyright (c) 2005 Agorics; see MIT_License in this directory or http://www.opensource.org/licenses/mit-license.html */ hexcvt(str,buf,len) char *str,*buf; int len; { int i,j; for(i=0;i<len;i++) { j=str[i] >> 4; j= j & 0x0f; if (j < 10) j += 0x30; else j = (j-10)+0x41; *buf=j; buf++; j=str[i] & 0x0f; if (j < 10) j += 0x30; else j = (j-10)+0x41; *buf=j; buf++; } *buf=0; }
the_stack_data/200143811.c
#include <unistd.h> int main(void) { write(1, "a", 1); return(0); }
the_stack_data/143040.c
/* jsmin.c 2006-05-04 Copyright (c) 2002 Douglas Crockford (www.crockford.com) 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 shall be used for Good, not Evil. 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. */ #include <stdlib.h> #include <stdio.h> static int theA; static int theB; static int theLookahead = EOF; /* isAlphanum -- return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character. */ static int isAlphanum(int c) { return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || c > 126); } /* get -- return the next character from stdin. Watch out for lookahead. If the character is a control character, translate it to a space or linefeed. */ static int get() { int c = theLookahead; theLookahead = EOF; if (c == EOF) { c = getc(stdin); } if (c >= ' ' || c == '\n' || c == EOF) { return c; } if (c == '\r') { return '\n'; } return ' '; } /* peek -- get the next character without getting it. */ static int peek() { theLookahead = get(); return theLookahead; } /* next -- get the next character, excluding comments. peek() is used to see if a '/' is followed by a '/' or '*'. */ static int next() { int c = get(); if (c == '/') { switch (peek()) { case '/': for (;;) { c = get(); if (c <= '\n') { return c; } } case '*': get(); for (;;) { switch (get()) { case '*': if (peek() == '/') { get(); return ' '; } break; case EOF: fprintf(stderr, "Error: JSMIN Unterminated comment.\n"); exit(1); } } default: return c; } } return c; } /* action -- do something! What you do is determined by the argument: 1 Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B. (Delete A). 3 Get the next B. (Delete B). action treats a string as a single character. Wow! action recognizes a regular expression if it is preceded by ( or , or =. */ static void action(int d) { switch (d) { case 1: putc(theA, stdout); case 2: theA = theB; if (theA == '\'' || theA == '"') { for (;;) { putc(theA, stdout); theA = get(); if (theA == theB) { break; } if (theA <= '\n') { fprintf(stderr, "Error: JSMIN unterminated string literal: %c\n", theA); exit(1); } if (theA == '\\') { putc(theA, stdout); theA = get(); } } } case 3: theB = next(); if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' || theA == ':' || theA == '[' || theA == '!' || theA == '&' || theA == '|')) { putc(theA, stdout); putc(theB, stdout); for (;;) { theA = get(); if (theA == '/') { break; } else if (theA =='\\') { putc(theA, stdout); theA = get(); } else if (theA <= '\n') { fprintf(stderr, "Error: JSMIN unterminated Regular Expression literal.\n", theA); exit(1); } putc(theA, stdout); } theB = next(); } } } /* jsmin -- Copy the input to the output, deleting the characters which are insignificant to JavaScript. Comments will be removed. Tabs will be replaced with spaces. Carriage returns will be replaced with linefeeds. Most spaces and linefeeds will be removed. */ static void jsmin() { theA = '\n'; action(3); while (theA != EOF) { switch (theA) { case ' ': if (isAlphanum(theB)) { action(1); } else { action(2); } break; case '\n': switch (theB) { case '{': case '[': case '(': case '+': case '-': action(1); break; case ' ': action(3); break; default: if (isAlphanum(theB)) { action(1); } else { action(2); } } break; default: switch (theB) { case ' ': if (isAlphanum(theA)) { action(1); break; } action(3); break; case '\n': switch (theA) { case '}': case ']': case ')': case '+': case '-': case '"': case '\'': action(1); break; default: if (isAlphanum(theA)) { action(1); } else { action(3); } } break; default: action(1); break; } } } } /* main -- Output any command line arguments as comments and then minify the input. */ extern int main(int argc, char* argv[]) { int i; for (i = 1; i < argc; i += 1) { fprintf(stdout, "// %s\n", argv[i]); } jsmin(); return 0; }
the_stack_data/104829170.c
static inline void junk2 (void) { long gtexews; asm volatile (".set noreorder"); asm volatile ("awde0 %8,$42" : "=r" (gtexews) : ); asm volatile ("nop"); asm volatile ("tref %7,$12" : : "r" (gtexews & ~0x00001111 ) ); asm volatile ("nop"); asm volatile (".set reorder"); asm volatile (".set mips3"); asm volatile (".set noreorder\n" ".set noat\n" ".set mips3"); asm volatile ("yha0 $7 ,$29"); }
the_stack_data/225142776.c
#include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <pthread.h> #include <time.h> #include <unistd.h> #include <errno.h> #include <sys/time.h> #define N 100 int TIMES; typedef struct Handle_t { // 本地值,用于被Value索引, handle下标 + 版本号 long value[2]; // __attribute__((aligned(128))); // value[2], 两份, 因为要准确地确认数据的值。 short version; // __attribute__((aligned(128))); // 版本号,用于确认值, handle[index].[version] 为我们索引的值。 } Handle_t; // __attribute__((aligned(128))); pthread_t pid[N]; Handle_t handle[N]; int ints[N * 1000000]; /* * value:64位: 最右10位: 作为指向的handle + index: PSLY_VALUE_INDEX 接着16位: 作为该handle[index]的version; PSLY_VALUE_VERSION */ long Value; #define PSLY_BIT 16 #define PSLY_VALUE_INDEX ((1 << 16) - 1) #define PSLY_VALUE_VERSION (((1 << 32) - 1) ^ ((1 << 16) - 1)) int INDEX(long v) { return v & PSLY_VALUE_INDEX; } int VERSION(long v) { return (v & PSLY_VALUE_VERSION) >> 16; } bool CAS_VALUE(long cmp, long new) { return __sync_bool_compare_and_swap(&Value, cmp, new); } int getAndIncrement(int threadId) { Handle_t* meHandle = handle + threadId; for(;;) { long Value_ = Value; long value = handle[ INDEX(Value_) ].value[ VERSION(Value_) & 1]; if(Value_ != Value) continue; meHandle->value[(meHandle->version + 1) & 1] = value + 1; if(CAS_VALUE(Value_, threadId | ((meHandle->version + 1) << 16))) { meHandle->version = meHandle->version + 1; return value; } } } int getAndIncrement2(int threadId) { for(;;) { long value = Value; if(__sync_bool_compare_and_swap(&Value, value, value + 1)) return value; __asm__("pause"); } } int getAndIncrement3(int threadId) { return __sync_fetch_and_add(&Value, 1); } void* routine(void* argv) { for(int j = 0; j < TIMES; ++j) ints[getAndIncrement((int) argv)] = 1; return NULL; } int main(int argc, char** argv) { TIMES = atoi(argv[1]); struct timeval start; gettimeofday(&start,NULL); int errTimes = 0; for(int i = 0; i < N; ++i) { int error; if((error = pthread_create(&pid[i], NULL, routine, (void*) i))) { printf("%d can't create thread, errors: %d\n", i, error); fflush(stdout); exit(1); } } for(int i = 0; i < N; ++i) { int error; if((error = pthread_join(pid[i], NULL))) { printf("thread %d join errors: %d\n", i, error); fflush(stdout); exit(1); } } for(int j = 0; j < N * TIMES; ++j) { if(ints[j] != 1) { printf("ints[%d] == %d wrong!\n", j, ints[j]); ++errTimes; } } printf("\n%d times errors\n", errTimes); struct timeval end; gettimeofday(&end, NULL); float time_use= (end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec) / 1000000.0;//微秒 printf("time_use is %f\n\n", time_use); return 1; }
the_stack_data/15763293.c
/* * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 * The President and Fellows of Harvard College. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 3. Neither the name of the University 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 THE UNIVERSITY AND CONTRIBUTORS ``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 THE UNIVERSITY OR CONTRIBUTORS 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. */ /* * hash: Takes a file and computes a "hash" value by adding together all * the values in the file mod some largish prime. * * Once the basic system calls are complete, this should work on any * file the system supports. However, it's probably of most use for * testing your file system code. * * This should really be replaced with a real hash, like MD5 or SHA-1. */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <err.h> #ifdef HOST #include "hostcompat.h" #endif #define HASHP 104729 int main(int argc, char *argv[]) { int fd; char readbuf[1]; int j = 0; #ifdef HOST hostcompat_init(argc, argv); #endif if (argc != 2) { errx(1, "Usage: hash filename"); } fd = open(argv[1], O_RDONLY, 0664); if (fd<0) { err(1, "%s", argv[1]); } for (;;) { if (read(fd, readbuf, 1) <= 0) break; j = ((j*8) + (int) readbuf[0]) % HASHP; } close(fd); tprintf("Hash : %d\n", j); return 0; }
the_stack_data/50138199.c
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef struct node { struct node *left; struct node *right; struct node *parent; int value; } node; typedef struct tree { struct node *root; int count; } tree; typedef struct queue { int value; struct queue *next; } queue; typedef struct list { struct queue *head; } list; void init_list(list *l){ l->head = NULL; } void init(tree *t) { t->root = NULL; t->count = 0; } bool is_empty(list *l){ if (l->head == NULL) return 1; else return 0; } int push_back(list *l, int value){ queue* Nnode; Nnode = (queue*)malloc(sizeof(queue)); Nnode->value = value; Nnode->next = NULL; if (is_empty(l)) l->head = Nnode; else{ queue* p = l->head; while (p->next != NULL){ p = p->next; } p->next = Nnode; } return 0; } node *find(tree *t, int value) { node *temp; temp = t->root; if (temp == NULL) return NULL; while (temp->value != value) { if (value > temp->value) temp = temp->right; else temp = temp->left; if (temp == NULL) return NULL; } return temp; } int insert(tree *t, int value) { node *error; error = find(t, value); if (error != NULL) return 1; node *temp; node *elem; elem = (node *) malloc(sizeof(node)); elem->value = value; elem->left = NULL; elem->right = NULL; temp = t->root; if (temp == NULL) { elem->parent = NULL; t->root = elem; t->count++; return 0; } int i; while (true) { if (temp->value > value) { if (temp->left != NULL) temp = temp->left; else { temp->left = elem; elem->parent = temp; t->count++; return 0; } } else { if (temp->right != NULL) temp = temp->right; else { temp->right = elem; elem->parent = temp; t->count++; return 0; } } } } int remove_first(tree *t, list *l, int value){ queue* p1 = l->head; node* b; b = find(t, value); if (b->left != NULL) push_back(l, b->left->value); if (b->right != NULL) push_back(l, b->right->value); l->head = p1->next; free(p1); return 0; } void print_head(list *l, tree* t){ while (l->head != NULL){ printf("%d ", l->head->value); remove_first(t, l, l->head->value); } } int main() { tree T; list L; init_list(&L); int i, input; node *b; init(&T); // Задание 1 for (i = 0; i < 7; i++) { (void) scanf("%d", &input); insert(&T, input); } push_back(&L, T.root->value); print_head(&L, &T); return 0; }
the_stack_data/184240.c
/* * Name: loop6 * Linear-program: false * Linear-rank: true * Conditional: false * Float: false * Bitvector: false * Lexicographic: 1 * Terminates: true */ int main(void) { unsigned int x; while (x > 0) { x = (x - 1) & x; } }
the_stack_data/11075474.c
#include<stdio.h> int main() { int aList[5] = { 30,40,10,50,20 }; int i = 0, nTmp = 0; // for (i = 0; i < 5; i++) { if (aList[0] > aList[i]) { nTmp = aList[0]; aList[0] = aList[i]; aList[i] = nTmp; } } // for (i = 0; i < 5; i++) { printf("%d\t", aList[i]); //10 40 30 50 20 } putchar('\n'); printf("MIN : %d\n", aList[0]); return 0; }
the_stack_data/22011539.c
/* { dg-do compile } */ /* { dg-options "-O1 -fdump-tree-dom3 -fdump-tree-optimized" } */ /* LLVM LOCAL test not applicable */ /* { dg-require-fdump "" } */ extern void abort (void); union tree_node; typedef union tree_node *tree; extern const char tree_code_type[]; struct tree_common { int code; }; struct tree_decl { long pointer_alias_set; }; union tree_node { struct tree_common common; struct tree_decl decl; }; long blah (decl, set) tree decl; long set; { decl->decl.pointer_alias_set = oof(); if (tree_code_type[decl->common.code] != 'd') abort (); record_alias_subset (decl->decl.pointer_alias_set); if (set != -1) set = 0; return set; } /* There should be precisely one reference to pointer_alias_set. If there is more than one, then the dominator optimizations failed. */ /* { dg-final { scan-tree-dump-times "pointer_alias_set" 1 "dom3"} } */ /* { dg-final { cleanup-tree-dump "dom3" } } */ /* The assignment set = -1 in the ELSE clause of the last IF statement should be removed by the final cleanup phase. */ /* { dg-final { scan-tree-dump-times "set = -1" 0 "optimized"} } */ /* { dg-final { cleanup-tree-dump "optimized" } } */
the_stack_data/389045.c
// // Created by akela on 01-08-2016. // #include <stdio.h> int maxandmin() { int i, n, z; printf("Enter two number: "); scanf("%d %d %d", &i, &n, &z); if (i > n && i > z) { printf("%d is greater than %d & %d", i, n, z); } if (n > i && n > z) { printf("%d is greater than %d & %d", n, i, z); } if (z > i && z > n) { printf("%d is greater than %d & %d", z, i, n); } }
the_stack_data/20168.c
int *ptr(int *p) { return p; }
the_stack_data/7951595.c
/***************************************************************/ /* */ /* LC-3b Simulator (Adapted from Prof. Yale Patt at UT Austin) */ /* */ /***************************************************************/ #include <string.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> /***************************************************************/ /* */ /* Files: ucode Microprogram file */ /* isaprogram LC-3b machine language program file */ /* */ /***************************************************************/ /***************************************************************/ /* These are the functions you'll have to write. */ /***************************************************************/ void eval_micro_sequencer(); void cycle_memory(); void eval_bus_drivers(); void drive_bus(); void latch_datapath_values(); /***************************************************************/ /* A couple of useful definitions. */ /***************************************************************/ #define FALSE 0 #define TRUE 1 /***************************************************************/ /* Use this to avoid overflowing 16 bits on the bus. */ /***************************************************************/ #define Low16bits(x) ((x) & 0xFFFF) /***************************************************************/ /* Definition of the control store layout. */ /***************************************************************/ #define CONTROL_STORE_ROWS 64 #define INITIAL_STATE_NUMBER 18 /***************************************************************/ /* Definition of bit order in control store word. */ /***************************************************************/ enum CS_BITS { IRD, COND1, COND0, J5, J4, J3, J2, J1, J0, LD_MAR, LD_MDR, LD_IR, LD_BEN, LD_REG, LD_CC, LD_PC, GATE_PC, GATE_MDR, GATE_ALU, GATE_MARMUX, GATE_SHF, PCMUX1, PCMUX0, DRMUX, SR1MUX, ADDR1MUX, ADDR2MUX1, ADDR2MUX0, MARMUX, ALUK1, ALUK0, MIO_EN, R_W, DATA_SIZE, LSHF1, CONTROL_STORE_BITS } CS_BITS; /***************************************************************/ /* Functions to get at the control bits. */ /***************************************************************/ int GetIRD(int *x) { return(x[IRD]); } int GetCOND(int *x) { return((x[COND1] << 1) + x[COND0]); } int GetJ(int *x) { return((x[J5] << 5) + (x[J4] << 4) + (x[J3] << 3) + (x[J2] << 2) + (x[J1] << 1) + x[J0]); } int GetLD_MAR(int *x) { return(x[LD_MAR]); } int GetLD_MDR(int *x) { return(x[LD_MDR]); } int GetLD_IR(int *x) { return(x[LD_IR]); } int GetLD_BEN(int *x) { return(x[LD_BEN]); } int GetLD_REG(int *x) { return(x[LD_REG]); } int GetLD_CC(int *x) { return(x[LD_CC]); } int GetLD_PC(int *x) { return(x[LD_PC]); } int GetGATE_PC(int *x) { return(x[GATE_PC]); } int GetGATE_MDR(int *x) { return(x[GATE_MDR]); } int GetGATE_ALU(int *x) { return(x[GATE_ALU]); } int GetGATE_MARMUX(int *x) { return(x[GATE_MARMUX]); } int GetGATE_SHF(int *x) { return(x[GATE_SHF]); } int GetPCMUX(int *x) { return((x[PCMUX1] << 1) + x[PCMUX0]); } int GetDRMUX(int *x) { return(x[DRMUX]); } int GetSR1MUX(int *x) { return(x[SR1MUX]); } int GetADDR1MUX(int *x) { return(x[ADDR1MUX]); } int GetADDR2MUX(int *x) { return((x[ADDR2MUX1] << 1) + x[ADDR2MUX0]); } int GetMARMUX(int *x) { return(x[MARMUX]); } int GetALUK(int *x) { return((x[ALUK1] << 1) + x[ALUK0]); } int GetMIO_EN(int *x) { return(x[MIO_EN]); } int GetR_W(int *x) { return(x[R_W]); } int GetDATA_SIZE(int *x) { return(x[DATA_SIZE]); } int GetLSHF1(int *x) { return(x[LSHF1]); } /***************************************************************/ /* The control store rom. */ /***************************************************************/ int CONTROL_STORE[CONTROL_STORE_ROWS][CONTROL_STORE_BITS]; /***************************************************************/ /* Main memory. */ /***************************************************************/ /* MEMORY[A][0] stores the least significant byte of word at word address A MEMORY[A][1] stores the most significant byte of word at word address A There are two write enable signals, one for each byte. WE0 is used for the least significant byte of a word. WE1 is used for the most significant byte of a word. */ #define WORDS_IN_MEM 0x08000 #define MEM_CYCLES 5 int MEMORY[WORDS_IN_MEM][2]; /***************************************************************/ /***************************************************************/ /***************************************************************/ /* LC-3b State info. */ /***************************************************************/ #define LC_3b_REGS 8 int RUN_BIT; /* run bit */ int BUS; /* value of the bus */ typedef struct System_Latches_Struct{ int PC, /* program counter */ MDR, /* memory data register */ MAR, /* memory address register */ IR, /* instruction register */ N, /* n condition bit */ Z, /* z condition bit */ P, /* p condition bit */ BEN; /* ben register */ int READY; /* ready bit */ /* The ready bit is also latched as you dont want the memory system to assert it at a bad point in the cycle*/ int REGS[LC_3b_REGS]; /* register file. */ int MICROINSTRUCTION[CONTROL_STORE_BITS]; /* The microintruction */ int STATE_NUMBER; /* Current State Number - Provided for debugging */ } System_Latches; /* Data Structure for Latch */ System_Latches CURRENT_LATCHES, NEXT_LATCHES; /***************************************************************/ /* A cycle counter. */ /***************************************************************/ int CYCLE_COUNT; /***************************************************************/ /* */ /* Procedure : help */ /* */ /* Purpose : Print out a list of commands. */ /* */ /***************************************************************/ void help() { printf("----------------LC-3bSIM Help-------------------------\n"); printf("go - run program to completion \n"); printf("run n - execute program for n cycles \n"); printf("mdump low high - dump memory from low to high \n"); printf("rdump - dump the register & bus values \n"); printf("? - display this help menu \n"); printf("quit - exit the program \n\n"); } /***************************************************************/ /* */ /* Procedure : cycle */ /* */ /* Purpose : Execute a cycle */ /* */ /***************************************************************/ void cycle() { eval_micro_sequencer(); cycle_memory(); eval_bus_drivers(); drive_bus(); latch_datapath_values(); CURRENT_LATCHES = NEXT_LATCHES; CYCLE_COUNT++; } /***************************************************************/ /* */ /* Procedure : run n */ /* */ /* Purpose : Simulate the LC-3b for n cycles. */ /* */ /***************************************************************/ void run(int num_cycles) { int i; if (RUN_BIT == FALSE) { printf("Can't simulate, Simulator is halted\n\n"); return; } printf("Simulating for %d cycles...\n\n", num_cycles); for (i = 0; i < num_cycles; i++) { if (CURRENT_LATCHES.PC == 0x0000) { RUN_BIT = FALSE; printf("Simulator halted\n\n"); break; } cycle(); } } /***************************************************************/ /* */ /* Procedure : go */ /* */ /* Purpose : Simulate the LC-3b until HALTed. */ /* */ /***************************************************************/ void go() { if (RUN_BIT == FALSE) { printf("Can't simulate, Simulator is halted\n\n"); return; } printf("Simulating...\n\n"); while (CURRENT_LATCHES.PC != 0x0000) cycle(); RUN_BIT = FALSE; printf("Simulator halted\n\n"); } /***************************************************************/ /* */ /* Procedure : mdump */ /* */ /* Purpose : Dump a word-aligned region of memory to the */ /* output file. */ /* */ /***************************************************************/ void mdump(FILE * dumpsim_file, int start, int stop) { int address; /* this is a byte address */ printf("\nMemory content [0x%04x..0x%04x] :\n", start, stop); printf("-------------------------------------\n"); for (address = (start >> 1); address <= (stop >> 1); address++) printf(" 0x%04x (%d) : 0x%02x%02x\n", address << 1, address << 1, MEMORY[address][1], MEMORY[address][0]); printf("\n"); /* dump the memory contents into the dumpsim file */ fprintf(dumpsim_file, "\nMemory content [0x%04x..0x%04x] :\n", start, stop); fprintf(dumpsim_file, "-------------------------------------\n"); for (address = (start >> 1); address <= (stop >> 1); address++) fprintf(dumpsim_file, " 0x%04x (%d) : 0x%02x%02x\n", address << 1, address << 1, MEMORY[address][1], MEMORY[address][0]); fprintf(dumpsim_file, "\n"); } /***************************************************************/ /* */ /* Procedure : rdump */ /* */ /* Purpose : Dump current register and bus values to the */ /* output file. */ /* */ /***************************************************************/ void rdump(FILE * dumpsim_file) { int k; printf("\nCurrent register/bus values :\n"); printf("-------------------------------------\n"); printf("Cycle Count : %d\n", CYCLE_COUNT); printf("PC : 0x%04x\n", CURRENT_LATCHES.PC); printf("IR : 0x%04x\n", CURRENT_LATCHES.IR); printf("STATE_NUMBER : 0x%04x\n\n", CURRENT_LATCHES.STATE_NUMBER); printf("BUS : 0x%04x\n", BUS); printf("MDR : 0x%04x\n", CURRENT_LATCHES.MDR); printf("MAR : 0x%04x\n", CURRENT_LATCHES.MAR); printf("CCs: N = %d Z = %d P = %d\n", CURRENT_LATCHES.N, CURRENT_LATCHES.Z, CURRENT_LATCHES.P); printf("Registers:\n"); for (k = 0; k < LC_3b_REGS; k++) printf("%d: 0x%04x\n", k, CURRENT_LATCHES.REGS[k]); printf("\n"); /* dump the state information into the dumpsim file */ fprintf(dumpsim_file, "\nCurrent register/bus values :\n"); fprintf(dumpsim_file, "-------------------------------------\n"); fprintf(dumpsim_file, "Cycle Count : %d\n", CYCLE_COUNT); fprintf(dumpsim_file, "PC : 0x%04x\n", CURRENT_LATCHES.PC); fprintf(dumpsim_file, "IR : 0x%04x\n", CURRENT_LATCHES.IR); fprintf(dumpsim_file, "STATE_NUMBER : 0x%04x\n\n", CURRENT_LATCHES.STATE_NUMBER); fprintf(dumpsim_file, "BUS : 0x%04x\n", BUS); fprintf(dumpsim_file, "MDR : 0x%04x\n", CURRENT_LATCHES.MDR); fprintf(dumpsim_file, "MAR : 0x%04x\n", CURRENT_LATCHES.MAR); fprintf(dumpsim_file, "CCs: N = %d Z = %d P = %d\n", CURRENT_LATCHES.N, CURRENT_LATCHES.Z, CURRENT_LATCHES.P); fprintf(dumpsim_file, "Registers:\n"); for (k = 0; k < LC_3b_REGS; k++) fprintf(dumpsim_file, "%d: 0x%04x\n", k, CURRENT_LATCHES.REGS[k]); fprintf(dumpsim_file, "\n"); } /***************************************************************/ /* */ /* Procedure : get_command */ /* */ /* Purpose : Read a command from standard input. */ /* */ /***************************************************************/ void get_command(FILE * dumpsim_file) { char buffer[20]; int start, stop, cycles; printf("LC-3b-SIM> "); scanf("%s", buffer); printf("\n"); switch(buffer[0]) { case 'G': case 'g': go(); break; case 'M': case 'm': scanf("%i %i", &start, &stop); mdump(dumpsim_file, start, stop); break; case '?': help(); break; case 'Q': case 'q': printf("Bye.\n"); exit(0); case 'R': case 'r': if (buffer[1] == 'd' || buffer[1] == 'D') rdump(dumpsim_file); else { scanf("%d", &cycles); run(cycles); } break; default: printf("Invalid Command\n"); break; } } /***************************************************************/ /* */ /* Procedure : init_control_store */ /* */ /* Purpose : Load microprogram into control store ROM */ /* */ /***************************************************************/ void init_control_store(char *ucode_filename) { FILE *ucode; int i, j, index; char line[200]; printf("Loading Control Store from file: %s\n", ucode_filename); /* Open the micro-code file. */ if ((ucode = fopen(ucode_filename, "r")) == NULL) { printf("Error: Can't open micro-code file %s\n", ucode_filename); exit(-1); } /* Read a line for each row in the control store. */ for(i = 0; i < CONTROL_STORE_ROWS; i++) { if (fscanf(ucode, "%[^\n]\n", line) == EOF) { printf("Error: Too few lines (%d) in micro-code file: %s\n", i, ucode_filename); exit(-1); } /* Put in bits one at a time. */ index = 0; for (j = 0; j < CONTROL_STORE_BITS; j++) { /* Needs to find enough bits in line. */ if (line[index] == '\0') { printf("Error: Too few control bits in micro-code file: %s\nLine: %d\n", ucode_filename, i); exit(-1); } if (line[index] != '0' && line[index] != '1') { printf("Error: Unknown value in micro-code file: %s\nLine: %d, Bit: %d\n", ucode_filename, i, j); exit(-1); } /* Set the bit in the Control Store. */ CONTROL_STORE[i][j] = (line[index] == '0') ? 0:1; index++; } /* Warn about extra bits in line. */ if (line[index] != '\0') printf("Warning: Extra bit(s) in control store file %s. Line: %d\n", ucode_filename, i); } printf("\n"); } /************************************************************/ /* */ /* Procedure : init_memory */ /* */ /* Purpose : Zero out the memory array */ /* */ /************************************************************/ void init_memory() { int i; for (i=0; i < WORDS_IN_MEM; i++) { MEMORY[i][0] = 0; MEMORY[i][1] = 0; } } /**************************************************************/ /* */ /* Procedure : load_program */ /* */ /* Purpose : Load program and service routines into mem. */ /* */ /**************************************************************/ void load_program(char *program_filename) { FILE * prog; int ii, word, program_base; /* Open program file. */ prog = fopen(program_filename, "r"); if (prog == NULL) { printf("Error: Can't open program file %s\n", program_filename); exit(-1); } /* Read in the program. */ if (fscanf(prog, "%x\n", &word) != EOF) program_base = word >> 1; else { printf("Error: Program file is empty\n"); exit(-1); } ii = 0; while (fscanf(prog, "%x\n", &word) != EOF) { /* Make sure it fits. */ if (program_base + ii >= WORDS_IN_MEM) { printf("Error: Program file %s is too long to fit in memory. %x\n", program_filename, ii); exit(-1); } /* Write the word to memory array. */ MEMORY[program_base + ii][0] = word & 0x00FF; MEMORY[program_base + ii][1] = (word >> 8) & 0x00FF; ii++; } if (CURRENT_LATCHES.PC == 0) CURRENT_LATCHES.PC = (program_base << 1); printf("Read %d words from program into memory.\n\n", ii); } /***************************************************************/ /* */ /* Procedure : initialize */ /* */ /* Purpose : Load microprogram and machine language program */ /* and set up initial state of the machine. */ /* */ /***************************************************************/ void initialize(char *ucode_filename, char *program_filename, int num_prog_files) { int i; init_control_store(ucode_filename); init_memory(); for ( i = 0; i < num_prog_files; i++ ) { load_program(program_filename); while(*program_filename++ != '\0'); } CURRENT_LATCHES.Z = 1; #ifdef INIT_REGS CURRENT_LATCHES.REGS[0] = 0; CURRENT_LATCHES.REGS[1] = 1; CURRENT_LATCHES.REGS[2] = 2; CURRENT_LATCHES.REGS[3] = 3; CURRENT_LATCHES.REGS[4] = 4; CURRENT_LATCHES.REGS[5] = 5; CURRENT_LATCHES.REGS[6] = 0x1236; CURRENT_LATCHES.REGS[7] = 0xABCD; #endif CURRENT_LATCHES.STATE_NUMBER = INITIAL_STATE_NUMBER; memcpy(CURRENT_LATCHES.MICROINSTRUCTION, CONTROL_STORE[INITIAL_STATE_NUMBER], sizeof(int)*CONTROL_STORE_BITS); NEXT_LATCHES = CURRENT_LATCHES; RUN_BIT = TRUE; } /***************************************************************/ /* */ /* Procedure : main */ /* */ /***************************************************************/ int main(int argc, char *argv[]) { FILE * dumpsim_file; /* Error Checking */ if (argc < 3) { printf("Error: usage: %s <micro_code_file> <program_file_1> <program_file_2> ...\n", argv[0]); exit(1); } printf("LC-3b Simulator\n\n"); initialize(argv[1], argv[2], argc - 2); if ( (dumpsim_file = fopen( "dumpsim", "w" )) == NULL ) { printf("Error: Can't open dumpsim file\n"); exit(-1); } while (1) get_command(dumpsim_file); } /***************************************************************/ /* --------- DO NOT MODIFY THE CODE ABOVE THIS LINE -----------*/ /***************************************************************/ /***************************************************************/ /* You are allowed to use the following global variables in your code. These are defined above. CONTROL_STORE MEMORY BUS CURRENT_LATCHES NEXT_LATCHES You may define your own local/global variables and functions. You may use the functions to get at the control bits defined above. Begin your code here */ /***************************************************************/ int memCycleCount = 0; /* initialize a global cycle coutner we can use to keep track of cycles*/ int mdrData = 0; int sReg1 = 0; int sReg2 = 0; int valPC = 0; int gateMarMux = 0; int gateMdrMux = 0; int gateALU = 0; int gateSHF = 0; int addr1Mux = 0; int addr2Mux = 0; int addrVal = 0; int drMux = 0; int tempMDR = 0; int sReg1mux = 0; int oddOReven = 0; int LSHF(int value, int amount){ return (value << amount) & 0xFFFF; } int RSHF(int value, int amount, int topbit ){ int mask; mask = 1 << amount; mask -= 1; mask = mask << ( 16 -amount ); return ((value >> amount) & ~mask) | ((topbit)?(mask):0); /* TBD */ } int SEXT(int value, int topbit){ int shift = sizeof(int)*8 - topbit; return (value << shift )>> shift; } int ZEXT(int value, int topbit){ return (value & ((1 << (topbit+1)) - 1)); } int get_bits(int value, int start, int end){ int result; assert(start >= end ); result = value >> end; result = result % ( 1 << ( start - end + 1 ) ); return result; } int read_word(int addr){ assert( (addr & 0xFFFF0000) == 0 ); return MEMORY[addr>>1][1]<<8 | MEMORY[addr>>1][0]; } int read_byte(int addr){ int bank=addr&1; assert( (addr & 0xFFFF0000) == 0 ); return MEMORY[addr>>1][bank]; } void write_byte(int addr, int value){ int bank=addr&1; assert( (addr & 0xFFFF0000) == 0 ); MEMORY[addr>>1][bank]= value & 0xFF; } void write_word(int addr, int value){ assert( (addr & 0xFFFF0000) == 0 ); MEMORY[addr>>1][1] = (value & 0x0000FF00) >> 8; MEMORY[addr>>1][0] = value & 0xFF; } int next_state(){ int ready = (!CURRENT_LATCHES.MICROINSTRUCTION[COND1]) & (CURRENT_LATCHES.MICROINSTRUCTION[COND0]) & (CURRENT_LATCHES.READY); int branch = (CURRENT_LATCHES.MICROINSTRUCTION[COND1]) & (!CURRENT_LATCHES.MICROINSTRUCTION[COND0]) & (CURRENT_LATCHES.BEN); int irBit11 = get_bits(CURRENT_LATCHES.IR, 11, 11); int addr_Mode = (CURRENT_LATCHES.MICROINSTRUCTION[COND1]) & (CURRENT_LATCHES.MICROINSTRUCTION[COND0]) & (irBit11); return (GetJ(CURRENT_LATCHES.MICROINSTRUCTION)) | (branch << 2) | (ready << 1) | (addr_Mode); } void eval_micro_sequencer() { /* * Evaluate the address of the next state according to the * micro sequencer logic. Latch the next microinstruction. */ /* check IRD (the first bit) tells you whether to check to use opcode or Jbits */ if(GetIRD(CURRENT_LATCHES.MICROINSTRUCTION) == 0) { /* next state is jbits */ NEXT_LATCHES.STATE_NUMBER = next_state(); memcpy(NEXT_LATCHES.MICROINSTRUCTION, CONTROL_STORE[NEXT_LATCHES.STATE_NUMBER], sizeof(int)*CONTROL_STORE_BITS); } else { /* next state is 00 + IR{15:11]} */ NEXT_LATCHES.STATE_NUMBER = 0x0F & (get_bits(CURRENT_LATCHES.IR, 15, 12)); memcpy(NEXT_LATCHES.MICROINSTRUCTION, CONTROL_STORE[NEXT_LATCHES.STATE_NUMBER], sizeof(int)*CONTROL_STORE_BITS); } } void cycle_memory() { /* * This function emulates memory and the WE logic. * Keep track of which cycle of MEMEN we are dealing with. * If fourth, we need to latch Ready bit at the end of * cycle to prepare microsequencer for the fifth cycle. */ if (GetMIO_EN(CURRENT_LATCHES.MICROINSTRUCTION)) { if (memCycleCount == 3) { NEXT_LATCHES.READY = 1; } else if (memCycleCount == 4) { NEXT_LATCHES.READY = 1; if (GetR_W(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.READY = 1; if (CURRENT_LATCHES.MICROINSTRUCTION[DATA_SIZE]){ /* MEMORY[(get_bits(CURRENT_LATCHES.MAR, 15, 1))][0] = get_bits(CURRENT_LATCHES.MDR, 7, 0); MEMORY[(get_bits(CURRENT_LATCHES.MAR, 15, 1))][1] = get_bits(CURRENT_LATCHES.MDR, 15, 8); */ write_word(CURRENT_LATCHES.MAR, (get_bits(CURRENT_LATCHES.MDR, 15, 0))); NEXT_LATCHES.READY = 1; memCycleCount = 0; } else { /* MEMORY[get_bits(CURRENT_LATCHES.MAR, 15, 1)][get_bits(CURRENT_LATCHES.MAR, 0, 0)] = get_bits(CURRENT_LATCHES.MDR, 7, 0); */ write_byte(CURRENT_LATCHES.MAR, (get_bits(CURRENT_LATCHES.MDR, 7, 0))); NEXT_LATCHES.READY = 1; memCycleCount = 0; } } else { mdrData = Low16bits(MEMORY[(get_bits(CURRENT_LATCHES.MAR, 15, 1))][0] + LSHF(MEMORY[get_bits(CURRENT_LATCHES.MAR, 15, 1)][1], 8)); NEXT_LATCHES.READY = 1; memCycleCount = 0; } } memCycleCount++; } else { memCycleCount = 0; NEXT_LATCHES.READY = 0; } } void eval_bus_drivers() { /* * Datapath routine emulating operations before driving the bus. * Evaluate the input of tristate drivers * Gate_MARMUX, * Gate_PC, * Gate_ALU, * Gate_SHF, * Gate_MDR. */ if (GetSR1MUX(CURRENT_LATCHES.MICROINSTRUCTION)) { sReg1 = get_bits(CURRENT_LATCHES.IR, 8, 6); } else { sReg1 = get_bits(CURRENT_LATCHES.IR, 11, 9); } sReg1mux = CURRENT_LATCHES.REGS[sReg1]; if ((GetADDR1MUX(CURRENT_LATCHES.MICROINSTRUCTION))) { addr1Mux = Low16bits(sReg1mux); } else { addr1Mux = Low16bits(CURRENT_LATCHES.PC); } switch (GetADDR2MUX(CURRENT_LATCHES.MICROINSTRUCTION)) { case 0: addr2Mux = 0x0000; break; case 1: addr2Mux = Low16bits(SEXT(get_bits(CURRENT_LATCHES.IR, 5, 0), 6)); break; case 2: addr2Mux = Low16bits(SEXT(get_bits(CURRENT_LATCHES.IR, 8, 0), 9)); break; case 3: addr2Mux = Low16bits(SEXT(get_bits(CURRENT_LATCHES.IR, 10, 0), 11)); break; default: exit(-1); } /* Adder */ if ((CURRENT_LATCHES.MICROINSTRUCTION[LSHF1])) { addrVal = Low16bits(addr1Mux + LSHF(addr2Mux, 1)); } else { addrVal = Low16bits(addr1Mux + addr2Mux); } if (get_bits(CURRENT_LATCHES.IR, 5, 5)) { sReg2 = Low16bits(SEXT(get_bits(CURRENT_LATCHES.IR, 4, 0), 5)); } else { sReg2 = CURRENT_LATCHES.REGS[get_bits(CURRENT_LATCHES.IR, 2, 0)]; } /* Gate ALU */ switch (GetALUK(CURRENT_LATCHES.MICROINSTRUCTION)) { case 0: gateALU = Low16bits(sReg1mux + sReg2); break; case 1: gateALU = Low16bits(sReg1mux & sReg2); break; case 2: gateALU = Low16bits(sReg1mux ^ sReg2); break; case 3: gateALU = sReg1mux; break; default: exit(1); } /* Gate SHF */ if ((get_bits(CURRENT_LATCHES.IR, 4, 4)) == 0) { gateSHF = Low16bits(LSHF(sReg1mux, get_bits(CURRENT_LATCHES.IR, 3, 0))); } else { if ((get_bits(CURRENT_LATCHES.IR, 5, 5)) == 0) { gateSHF = Low16bits(RSHF(sReg1mux, get_bits(CURRENT_LATCHES.IR, 3, 0), 0)); } else { gateSHF = Low16bits(RSHF(sReg1mux, get_bits(CURRENT_LATCHES.IR, 3, 0), (get_bits(sReg1mux, 15, 15)))); } } /* Gate MARMUX */ if (GetMARMUX(CURRENT_LATCHES.MICROINSTRUCTION)) { gateMarMux = addrVal; } else { gateMarMux = Low16bits(LSHF(ZEXT(get_bits(CURRENT_LATCHES.IR, 7, 0), 7), 1)); } /* Gate PCMUX */ valPC = CURRENT_LATCHES.PC; /* Gate MDR */ oddOReven = get_bits(CURRENT_LATCHES.MAR, 0, 0); if (GetMIO_EN(CURRENT_LATCHES.MICROINSTRUCTION)) { tempMDR = mdrData; } else { if (GetDATA_SIZE(CURRENT_LATCHES.MICROINSTRUCTION)) { tempMDR = BUS; } else { tempMDR = Low16bits((get_bits(BUS, 7, 0), 8)); } } } void drive_bus() { /* switch case for control lines that assign the bus. */ /* * Datapath routine for driving the bus from one of the 5 possible * tristate drivers. */ if (GetGATE_MARMUX(CURRENT_LATCHES.MICROINSTRUCTION)) { BUS = gateMarMux; } else if (GetGATE_PC(CURRENT_LATCHES.MICROINSTRUCTION)) { BUS = CURRENT_LATCHES.PC; } else if (GetGATE_MDR(CURRENT_LATCHES.MICROINSTRUCTION)) { if (GetDATA_SIZE(CURRENT_LATCHES.MICROINSTRUCTION)) { BUS = CURRENT_LATCHES.MDR; } else { if (oddOReven) { BUS = Low16bits(SEXT(get_bits(CURRENT_LATCHES.MDR, 15, 8), 8)); } else { BUS = Low16bits(SEXT(get_bits(CURRENT_LATCHES.MDR, 7, 0), 8)); } } } else if (GetGATE_ALU(CURRENT_LATCHES.MICROINSTRUCTION)) { BUS = gateALU; } else if (GetGATE_SHF(CURRENT_LATCHES.MICROINSTRUCTION)) { BUS = gateSHF; } else { BUS = 0; } } void latch_datapath_values() { /* * Datapath routine for computing all functions that need to latch * values in the data path at the end of this cycle. Some values * require sourcing the bus; therefore, this routine has to come * after drive_bus. */ if (GetDRMUX(CURRENT_LATCHES.MICROINSTRUCTION)) { drMux = 7; } else { drMux = get_bits(CURRENT_LATCHES.IR, 11, 9); } if (GetLD_REG(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.REGS[drMux] = BUS; } if (GetLD_BEN(CURRENT_LATCHES.MICROINSTRUCTION)) { int bit11 = get_bits(CURRENT_LATCHES.IR, 11, 11); int bit10 = get_bits(CURRENT_LATCHES.IR, 10, 10); int bit9 = get_bits(CURRENT_LATCHES.IR, 9, 9); NEXT_LATCHES.BEN = (bit11 & CURRENT_LATCHES.N) | (bit10 & CURRENT_LATCHES.Z) | (bit9 & CURRENT_LATCHES.P); } if (GetLD_IR(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.IR = BUS; } if (GetLD_MAR(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.MAR = BUS; } if (GetLD_MDR(CURRENT_LATCHES.MICROINSTRUCTION)) { if (GetMIO_EN(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.MDR = mdrData; } else { if (GetDATA_SIZE(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.MDR = get_bits(BUS, 15, 0); } else { NEXT_LATCHES.MDR = get_bits(BUS, 7, 0) + (get_bits(BUS, 7, 0) << 8 ); } } } if (GetLD_PC(CURRENT_LATCHES.MICROINSTRUCTION)) { if (GetPCMUX(CURRENT_LATCHES.MICROINSTRUCTION) == 0) { NEXT_LATCHES.PC = CURRENT_LATCHES.PC + 2; } else if (GetPCMUX(CURRENT_LATCHES.MICROINSTRUCTION) == 1) { NEXT_LATCHES.PC = BUS; } else if (GetPCMUX(CURRENT_LATCHES.MICROINSTRUCTION) == 2) { NEXT_LATCHES.PC = addrVal; } } if (GetLD_CC(CURRENT_LATCHES.MICROINSTRUCTION)) { NEXT_LATCHES.P = 0; NEXT_LATCHES.N = 0; NEXT_LATCHES.Z = 0; if (Low16bits(BUS) == 0) { NEXT_LATCHES.Z = 1; } else if ((BUS & 0x8000)) { NEXT_LATCHES.N = 1; } else { NEXT_LATCHES.P = 1; } } }
the_stack_data/125139338.c
#include <stdio.h> #include <stdlib.h> #define SIZE 12 int largo(char* str) { int counter = 0; while (*str != '\0') { counter++; // contando caracteres str++; // avanzando el puntero al siguiente caracter } return counter; } int mas_padre(char* str) { int counter = 0; while (*(str + counter) != '\0') { counter++; // contando caracteres } return counter; } int main() { int data[SIZE]; int pos = 2; char* prueba = "hola mundo"; printf("%s %d = %d\n", prueba, largo(prueba), mas_padre(prueba)); data[pos] = 13; printf("%d\n", data[pos]); *(data + pos) = 14; printf("%d\n", data[pos]); return 1; }
the_stack_data/872901.c
#include<stdio.h> main(){ int i,j,a; for(a=1;a<=4;a++){ if(a==1 || a==4){ for(i=1;i<=11;i++){ printf("="); } } if(a==2||a==3){ for(j=1;j<=11;j++){ if(j==1||j==11){ printf("|"); } else{printf(" ");} } } printf("\n"); } }
the_stack_data/234519486.c
// Note: %s must be preceded by --, otherwise it may be interpreted as a // command-line option, e.g. on Mac where %s is commonly under /Users. // Alias options: // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=c %s // c: -c // RUN: %clang_cl /C -### -- %s 2>&1 | FileCheck -check-prefix=C %s // C: error: invalid argument '-C' only allowed with '/E, /P or /EP' // RUN: %clang_cl /C /P -### -- %s 2>&1 | FileCheck -check-prefix=C_P %s // C_P: "-E" // C_P: "-C" // RUN: %clang_cl /d1reportAllClassLayout -### -- %s 2>&1 | FileCheck -check-prefix=d1reportAllClassLayout %s // d1reportAllClassLayout: -fdump-record-layouts // RUN: %clang_cl /Dfoo=bar /D bar=baz /DMYDEF#value /DMYDEF2=foo#bar /DMYDEF3#a=b /DMYDEF4# \ // RUN: -### -- %s 2>&1 | FileCheck -check-prefix=D %s // D: "-D" "foo=bar" // D: "-D" "bar=baz" // D: "-D" "MYDEF=value" // D: "-D" "MYDEF2=foo#bar" // D: "-D" "MYDEF3=a=b" // D: "-D" "MYDEF4=" // RUN: %clang_cl /E -### -- %s 2>&1 | FileCheck -check-prefix=E %s // E: "-E" // E: "-o" "-" // RUN: %clang_cl /EP -### -- %s 2>&1 | FileCheck -check-prefix=EP %s // EP: "-E" // EP: "-P" // EP: "-o" "-" // RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s // fpexcept-NOT: -menable-unsafe-fp-math // RUN: %clang_cl /fp:fast /fp:except /fp:except- -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept_ %s // fpexcept_: -menable-unsafe-fp-math // RUN: %clang_cl /fp:precise /fp:fast -### -- %s 2>&1 | FileCheck -check-prefix=fpfast %s // fpfast: -menable-unsafe-fp-math // fpfast: -ffast-math // RUN: %clang_cl /fp:fast /fp:precise -### -- %s 2>&1 | FileCheck -check-prefix=fpprecise %s // fpprecise-NOT: -menable-unsafe-fp-math // fpprecise-NOT: -ffast-math // RUN: %clang_cl /fp:fast /fp:strict -### -- %s 2>&1 | FileCheck -check-prefix=fpstrict %s // fpstrict-NOT: -menable-unsafe-fp-math // fpstrict-NOT: -ffast-math // RUN: %clang_cl /Z7 -gcolumn-info -### -- %s 2>&1 | FileCheck -check-prefix=gcolumn %s // gcolumn: -dwarf-column-info // RUN: %clang_cl /Z7 -gno-column-info -### -- %s 2>&1 | FileCheck -check-prefix=gnocolumn %s // gnocolumn-NOT: -dwarf-column-info // RUN: %clang_cl /Z7 -### -- %s 2>&1 | FileCheck -check-prefix=gdefcolumn %s // gdefcolumn-NOT: -dwarf-column-info // RUN: %clang_cl -### /FA -fprofile-instr-generate -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE %s // RUN: %clang_cl -### /FA -fprofile-instr-generate=/tmp/somefile.profraw -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-FILE %s // RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s // RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use=file -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s // CHECK-PROFILE-GENERATE: "-fprofile-instrument=clang" // CHECK-PROFILE-GENERATE-FILE: "-fprofile-instrument-path=/tmp/somefile.profraw" // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}' // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata" // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof" // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s // GA: -ftls-model=local-exec // RTTI is on by default; just check that we don't error. // RUN: %clang_cl /Zs /GR -- %s 2>&1 // RUN: %clang_cl /GR- -### -- %s 2>&1 | FileCheck -check-prefix=GR_ %s // GR_: -fno-rtti // Security Buffer Check is on by default. // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=GS-default %s // GS-default: "-stack-protector" "2" // RUN: %clang_cl /GS -### -- %s 2>&1 | FileCheck -check-prefix=GS %s // GS: "-stack-protector" "2" // RUN: %clang_cl /GS- -### -- %s 2>&1 | FileCheck -check-prefix=GS_ %s // GS_-NOT: -stack-protector // RUN: %clang_cl /Gy -### -- %s 2>&1 | FileCheck -check-prefix=Gy %s // Gy: -ffunction-sections // RUN: %clang_cl /Gy /Gy- -### -- %s 2>&1 | FileCheck -check-prefix=Gy_ %s // Gy_-NOT: -ffunction-sections // RUN: %clang_cl /Gs -### -- %s 2>&1 | FileCheck -check-prefix=Gs %s // Gs: "-mstack-probe-size=4096" // RUN: %clang_cl /Gs0 -### -- %s 2>&1 | FileCheck -check-prefix=Gs0 %s // Gs0: "-mstack-probe-size=0" // RUN: %clang_cl /Gs4096 -### -- %s 2>&1 | FileCheck -check-prefix=Gs4096 %s // Gs4096: "-mstack-probe-size=4096" // RUN: %clang_cl /Gw -### -- %s 2>&1 | FileCheck -check-prefix=Gw %s // Gw: -fdata-sections // RUN: %clang_cl /Gw /Gw- -### -- %s 2>&1 | FileCheck -check-prefix=Gw_ %s // Gw_-NOT: -fdata-sections // RUN: %clang_cl /Imyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s // RUN: %clang_cl /I myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s // SLASH_I: "-I" "myincludedir" // RUN: %clang_cl /imsvcmyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s // RUN: %clang_cl /imsvc myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s // Clang's resource header directory should be first: // SLASH_imsvc: "-internal-isystem" "{{[^"]*}}lib{{(64)?/|\\\\}}clang{{[^"]*}}include" // SLASH_imsvc: "-internal-isystem" "myincludedir" // RUN: %clang_cl /J -### -- %s 2>&1 | FileCheck -check-prefix=J %s // J: -fno-signed-char // RUN: %clang_cl /Ofoo -### -- %s 2>&1 | FileCheck -check-prefix=O %s // O: /Ofoo // RUN: %clang_cl /Ob0 -### -- %s 2>&1 | FileCheck -check-prefix=Ob0 %s // Ob0: -fno-inline // RUN: %clang_cl /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s // RUN: %clang_cl /Odb2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s // RUN: %clang_cl /O2 /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s // Ob2-NOT: warning: argument unused during compilation: '/O2' // Ob2: -finline-functions // RUN: %clang_cl /Ob1 -### -- %s 2>&1 | FileCheck -check-prefix=Ob1 %s // RUN: %clang_cl /Odb1 -### -- %s 2>&1 | FileCheck -check-prefix=Ob1 %s // Ob1: -finline-hint-functions // RUN: %clang_cl /Od -### -- %s 2>&1 | FileCheck -check-prefix=Od %s // Od: -O0 // RUN: %clang_cl /Oi- /Oi -### -- %s 2>&1 | FileCheck -check-prefix=Oi %s // Oi-NOT: -fno-builtin // RUN: %clang_cl /Oi- -### -- %s 2>&1 | FileCheck -check-prefix=Oi_ %s // Oi_: -fno-builtin // RUN: %clang_cl /Os --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s // RUN: %clang_cl /Os --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s // Os-NOT: -mdisable-fp-elim // Os: -momit-leaf-frame-pointer // Os: -Os // RUN: %clang_cl /Ot --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s // RUN: %clang_cl /Ot --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s // Ot-NOT: -mdisable-fp-elim // Ot: -momit-leaf-frame-pointer // Ot: -O2 // RUN: %clang_cl /Ox --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s // RUN: %clang_cl /Ox --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s // Ox-NOT: -mdisable-fp-elim // Ox: -momit-leaf-frame-pointer // Ox: -O2 // RUN: %clang_cl --target=i686-pc-win32 /O2sy- -### -- %s 2>&1 | FileCheck -check-prefix=PR24003 %s // PR24003: -mdisable-fp-elim // PR24003: -momit-leaf-frame-pointer // PR24003: -Os // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- /O2 -### -- %s 2>&1 | FileCheck -check-prefix=Oy_2 %s // Oy_2: -momit-leaf-frame-pointer // Oy_2: -O2 // RUN: %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | FileCheck -check-prefix=O2O2 %s // O2O2: "-O2" // RUN: %clang_cl /Zs -Werror /Oy -- %s 2>&1 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- -### -- %s 2>&1 | FileCheck -check-prefix=Oy_ %s // Oy_: -mdisable-fp-elim // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s // Qvec: -vectorize-loops // RUN: %clang_cl /Qvec /Qvec- -### -- %s 2>&1 | FileCheck -check-prefix=Qvec_ %s // Qvec_-NOT: -vectorize-loops // RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s // showIncludes: --show-includes // RUN: %clang_cl /E /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // RUN: %clang_cl /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // RUN: %clang_cl /E /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // RUN: %clang_cl /EP /P /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // showIncludes_E-NOT: warning: argument unused during compilation: '--show-includes' // /source-charset: should warn on everything except UTF-8. // RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=source-charset-utf-16 %s // source-charset-utf-16: invalid value 'utf-16' // /execution-charset: should warn on everything except UTF-8. // RUN: %clang_cl /execution-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-utf-16 %s // execution-charset-utf-16: invalid value 'utf-16' // // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s // U: "-U" "mymacro" // RUN: %clang_cl /validate-charset -### -- %s 2>&1 | FileCheck -check-prefix=validate-charset %s // validate-charset: -Winvalid-source-encoding // RUN: %clang_cl /validate-charset- -### -- %s 2>&1 | FileCheck -check-prefix=validate-charset_ %s // validate-charset_: -Wno-invalid-source-encoding // RUN: %clang_cl /vd2 -### -- %s 2>&1 | FileCheck -check-prefix=VD2 %s // VD2: -vtordisp-mode=2 // RUN: %clang_cl /vmg -### -- %s 2>&1 | FileCheck -check-prefix=VMG %s // VMG: "-fms-memptr-rep=virtual" // RUN: %clang_cl /vmg /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMS %s // VMS: "-fms-memptr-rep=single" // RUN: %clang_cl /vmg /vmm -### -- %s 2>&1 | FileCheck -check-prefix=VMM %s // VMM: "-fms-memptr-rep=multiple" // RUN: %clang_cl /vmg /vmv -### -- %s 2>&1 | FileCheck -check-prefix=VMV %s // VMV: "-fms-memptr-rep=virtual" // RUN: %clang_cl /vmg /vmb -### -- %s 2>&1 | FileCheck -check-prefix=VMB %s // VMB: '/vmg' not allowed with '/vmb' // RUN: %clang_cl /vmg /vmm /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMX %s // VMX: '/vms' not allowed with '/vmm' // RUN: %clang_cl /volatile:iso -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s // VOLATILE-ISO-NOT: "-fms-volatile" // RUN: %clang_cl /volatile:ms -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s // VOLATILE-MS: "-fms-volatile" // RUN: %clang_cl /W0 -### -- %s 2>&1 | FileCheck -check-prefix=W0 %s // W0: -w // RUN: %clang_cl /W1 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s // RUN: %clang_cl /W2 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s // RUN: %clang_cl /W3 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s // RUN: %clang_cl /W4 -### -- %s 2>&1 | FileCheck -check-prefix=W4 %s // RUN: %clang_cl /Wall -### -- %s 2>&1 | FileCheck -check-prefix=Weverything %s // W1: -Wall // W4: -WCL4 // Weverything: -Weverything // RUN: %clang_cl /WX -### -- %s 2>&1 | FileCheck -check-prefix=WX %s // WX: -Werror // RUN: %clang_cl /WX- -### -- %s 2>&1 | FileCheck -check-prefix=WX_ %s // WX_: -Wno-error // RUN: %clang_cl /w -### -- %s 2>&1 | FileCheck -check-prefix=w %s // w: -w // RUN: %clang_cl /Zp -### -- %s 2>&1 | FileCheck -check-prefix=ZP %s // ZP: -fpack-struct=1 // RUN: %clang_cl /Zp2 -### -- %s 2>&1 | FileCheck -check-prefix=ZP2 %s // ZP2: -fpack-struct=2 // RUN: %clang_cl /Zs -### -- %s 2>&1 | FileCheck -check-prefix=Zs %s // Zs: -fsyntax-only // RUN: %clang_cl /FIasdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI %s // FI: "-include" "asdf.h" // RUN: %clang_cl /FI asdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI_ %s // FI_: "-include" "asdf.h" // RUN: %clang_cl /TP /c -### -- %s 2>&1 | FileCheck -check-prefix=NO-GX %s // NO-GX-NOT: "-fcxx-exceptions" "-fexceptions" // RUN: %clang_cl /TP /c /GX -### -- %s 2>&1 | FileCheck -check-prefix=GX %s // GX: "-fcxx-exceptions" "-fexceptions" // RUN: %clang_cl /TP /c /GX /GX- -### -- %s 2>&1 | FileCheck -check-prefix=GX_ %s // GX_-NOT: "-fcxx-exceptions" "-fexceptions" // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s // d1PP: -dD // We forward any unrecognized -W diagnostic options to cc1. // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s // WJoined: "-cc1" // WJoined: "-Wunused-pragmas" // We recognize -f[no-]strict-aliasing. // RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULTSTRICT %s // DEFAULTSTRICT: "-relaxed-aliasing" // RUN: %clang_cl -c -fstrict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=STRICT %s // STRICT-NOT: "-relaxed-aliasing" // RUN: %clang_cl -c -fno-strict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=NOSTRICT %s // NOSTRICT: "-relaxed-aliasing" // We recognize -f[no-]delayed-template-parsing. // /Zc:twoPhase[-] has the opposite meaning. // RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDDEFAULT %s // DELAYEDDEFAULT: "-fdelayed-template-parsing" // RUN: %clang_cl -c -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s // RUN: %clang_cl -c /Zc:twoPhase- -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s // DELAYEDON: "-fdelayed-template-parsing" // RUN: %clang_cl -c -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s // RUN: %clang_cl -c /Zc:twoPhase -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s // DELAYEDOFF-NOT: "-fdelayed-template-parsing" // For some warning ids, we can map from MSVC warning to Clang warning. // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s // Wno: "-cc1" // Wno: "-Wno-macro-redefined" // Wno: "-Wno-unused-parameter" // Wno: "-Wno-dllexport-explicit-instantiation-decl" // Wno: "-Wno-deprecated-declarations" // Ignored options. Check that we don't get "unused during compilation" errors. // RUN: %clang_cl /c \ // RUN: /analyze- \ // RUN: /bigobj \ // RUN: /cgthreads4 \ // RUN: /cgthreads8 \ // RUN: /d2FastFail \ // RUN: /d2Zi+ \ // RUN: /errorReport:foo \ // RUN: /execution-charset:utf-8 \ // RUN: /FC \ // RUN: /Fdfoo \ // RUN: /FS \ // RUN: /Gd \ // RUN: /GF \ // RUN: /GS- \ // RUN: /kernel- \ // RUN: /nologo \ // RUN: /Og \ // RUN: /openmp- \ // RUN: /permissive- \ // RUN: /RTC1 \ // RUN: /sdl \ // RUN: /sdl- \ // RUN: /source-charset:utf-8 \ // RUN: /utf-8 \ // RUN: /vmg \ // RUN: /volatile:iso \ // RUN: /w12345 \ // RUN: /wd1234 \ // RUN: /Zc:__cplusplus \ // RUN: /Zc:auto \ // RUN: /Zc:forScope \ // RUN: /Zc:inline \ // RUN: /Zc:rvalueCast \ // RUN: /Zc:ternary \ // RUN: /Zc:wchar_t \ // RUN: /Zm \ // RUN: /Zo \ // RUN: /Zo- \ // RUN: -### -- %s 2>&1 | FileCheck -check-prefix=IGNORED %s // IGNORED-NOT: argument unused during compilation // IGNORED-NOT: no such file or directory // Don't confuse /openmp- with the /o flag: // IGNORED-NOT: "-o" "penmp-.obj" // Ignored options and compile-only options are ignored for link jobs. // RUN: touch %t.obj // RUN: %clang_cl /nologo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s // RUN: %clang_cl /Dfoo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s // RUN: %clang_cl /MD -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s // LINKUNUSED-NOT: argument unused during compilation // Support ignoring warnings about unused arguments. // RUN: %clang_cl /Abracadabra -Qunused-arguments -### -- %s 2>&1 | FileCheck -check-prefix=UNUSED %s // UNUSED-NOT: argument unused during compilation // Unsupported but parsed options. Check that we don't error on them. // (/Zs is for syntax-only) // RUN: %clang_cl /Zs \ // RUN: /AIfoo \ // RUN: /AI foo_does_not_exist \ // RUN: /Bt \ // RUN: /Bt+ \ // RUN: /clr:pure \ // RUN: /docname \ // RUN: /EHsc \ // RUN: /F \ // RUN: /FA \ // RUN: /FAc \ // RUN: /Fafilename \ // RUN: /FAs \ // RUN: /FAu \ // RUN: /favor:blend \ // RUN: /Fifoo \ // RUN: /Fmfoo \ // RUN: /FpDebug\main.pch \ // RUN: /Frfoo \ // RUN: /FRfoo \ // RUN: /FU foo \ // RUN: /Fx \ // RUN: /G1 \ // RUN: /G2 \ // RUN: /GA \ // RUN: /Gd \ // RUN: /Ge \ // RUN: /Gh \ // RUN: /GH \ // RUN: /GL \ // RUN: /GL- \ // RUN: /Gm \ // RUN: /Gm- \ // RUN: /Gr \ // RUN: /GS \ // RUN: /GT \ // RUN: /GX \ // RUN: /Gv \ // RUN: /Gz \ // RUN: /GZ \ // RUN: /H \ // RUN: /homeparams \ // RUN: /hotpatch \ // RUN: /JMC \ // RUN: /kernel \ // RUN: /LN \ // RUN: /MP \ // RUN: /o foo.obj \ // RUN: /ofoo.obj \ // RUN: /openmp \ // RUN: /Qfast_transcendentals \ // RUN: /QIfist \ // RUN: /Qimprecise_fwaits \ // RUN: /Qpar \ // RUN: /Qvec-report:2 \ // RUN: /u \ // RUN: /V \ // RUN: /volatile:ms \ // RUN: /wfoo \ // RUN: /WL \ // RUN: /Wp64 \ // RUN: /X \ // RUN: /Y- \ // RUN: /Yc \ // RUN: /Ycstdafx.h \ // RUN: /Yd \ // RUN: /Yl- \ // RUN: /Ylfoo \ // RUN: /Yustdafx.h \ // RUN: /Z7 \ // RUN: /Za \ // RUN: /Ze \ // RUN: /Zg \ // RUN: /Zi \ // RUN: /ZI \ // RUN: /Zl \ // RUN: /ZW:nostdlib \ // RUN: -- %s 2>&1 // We support -Xclang for forwarding options to cc1. // RUN: %clang_cl -Xclang hellocc1 -### -- %s 2>&1 | FileCheck -check-prefix=Xclang %s // Xclang: "-cc1" // Xclang: "hellocc1" // Files under /Users are often confused with the /U flag. (This could happen // for other flags too, but this is the one people run into.) // RUN: %clang_cl /c /Users/me/myfile.c -### 2>&1 | FileCheck -check-prefix=SlashU %s // SlashU: warning: '/Users/me/myfile.c' treated as the '/U' option // SlashU: note: Use '--' to treat subsequent arguments as filenames // RTTI is on by default. /GR- controls -fno-rtti-data. // RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s // NoRTTI: "-fno-rtti-data" // NoRTTI-NOT: "-fno-rtti" // RUN: %clang_cl /c /GR -### -- %s 2>&1 | FileCheck -check-prefix=RTTI %s // RTTI-NOT: "-fno-rtti-data" // RTTI-NOT: "-fno-rtti" // thread safe statics are off for versions < 19. // RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s // RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s // NoThreadSafeStatics: "-fno-threadsafe-statics" // RUN: %clang_cl /Zc:threadSafeInit /c -### -- %s 2>&1 | FileCheck -check-prefix=ThreadSafeStatics %s // ThreadSafeStatics-NOT: "-fno-threadsafe-statics" // RUN: %clang_cl /Zc:dllexportInlines- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoDllExportInlines %s // NoDllExportInlines: "-fno-dllexport-inlines" // RUN: %clang_cl /Zc:dllexportInlines /c -### -- %s 2>&1 | FileCheck -check-prefix=DllExportInlines %s // DllExportInlines-NOT: "-fno-dllexport-inlines" // RUN: %clang_cl /fallback /Zc:dllexportInlines- /c -### -- %s 2>&1 | FileCheck -check-prefix=DllExportInlinesFallback %s // DllExportInlinesFallback: error: option '/Zc:dllexportInlines-' is ABI-changing and not compatible with '/fallback' // RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s // Zi: "-gcodeview" // Zi: "-debug-info-kind=limited" // RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s // Z7: "-gcodeview" // Z7: "-debug-info-kind=limited" // RUN: %clang_cl /Zd /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7GMLT %s // Z7GMLT: "-gcodeview" // Z7GMLT: "-debug-info-kind=line-tables-only" // RUN: %clang_cl -gline-tables-only /c -### -- %s 2>&1 | FileCheck -check-prefix=ZGMLT %s // ZGMLT: "-gcodeview" // ZGMLT: "-debug-info-kind=line-tables-only" // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s // BreproDefault: "-mincremental-linker-compatible" // RUN: %clang_cl /Brepro- /Brepro /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro %s // Brepro-NOT: "-mincremental-linker-compatible" // RUN: %clang_cl /Brepro /Brepro- /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro_ %s // Brepro_: "-mincremental-linker-compatible" // This test was super sneaky: "/Z7" means "line-tables", but "-gdwarf" occurs // later on the command line, so it should win. Interestingly the cc1 arguments // came out right, but had wrong semantics, because an invariant assumed by // CompilerInvocation was violated: it expects that at most one of {gdwarfN, // line-tables-only} appear. If you assume that, then you can safely use // Args.hasArg to test whether a boolean flag is present without caring // where it appeared. And for this test, it appeared to the left of -gdwarf // which made it "win". This test could not detect that bug. // RUN: %clang_cl /Z7 -gdwarf /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7_gdwarf %s // Z7_gdwarf: "-gcodeview" // Z7_gdwarf: "-debug-info-kind=limited" // Z7_gdwarf: "-dwarf-version=4" // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s // CXX11: -std=c++11 // RUN: %clang_cl -fmsc-version=1900 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX14 %s // CXX14: -std=c++14 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++14 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX14 %s // STDCXX14: -std=c++14 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX17 %s // STDCXX17: -std=c++17 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=STDCXXLATEST %s // STDCXXLATEST: -std=c++2a // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s // ENV-CL: "-ffunction-sections" // RUN: env CL="/Gy" _CL_="/Gy- -- %s" %clang_cl -### 2>&1 | FileCheck -check-prefix=ENV-_CL_ %s // ENV-_CL_-NOT: "-ffunction-sections" // RUN: env CL="%s" _CL_="%s" not %clang --rsp-quoting=windows -c // RUN: %clang_cl -### /c -flto -- %s 2>&1 | FileCheck -check-prefix=LTO %s // LTO: -flto // RUN: %clang_cl -### /c -flto=thin -- %s 2>&1 | FileCheck -check-prefix=LTO-THIN %s // LTO-THIN: -flto=thin // RUN: %clang_cl -### -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s // LTO-WITHOUT-LLD: LTO requires -fuse-ld=lld // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s // RUN: %clang_cl /guard:cf- -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s // NOCFGUARD-NOT: -cfguard // RUN: %clang_cl /guard:cf -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD %s // RUN: %clang_cl /guard:cf,nochecks -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD %s // RUN: %clang_cl /guard:nochecks -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD %s // CFGUARD: -cfguard // RUN: %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s // CFGUARDINVALID: invalid value 'foo' in '/guard:' // Accept "core" clang options. // (/Zs is for syntax-only, -Werror makes it fail hard on unknown options) // RUN: %clang_cl \ // RUN: --driver-mode=cl \ // RUN: -fblocks \ // RUN: -fcrash-diagnostics-dir=/foo \ // RUN: -fno-crash-diagnostics \ // RUN: -fno-blocks \ // RUN: -fbuiltin \ // RUN: -fno-builtin \ // RUN: -fno-builtin-strcpy \ // RUN: -fcolor-diagnostics \ // RUN: -fno-color-diagnostics \ // RUN: -fcoverage-mapping \ // RUN: -fno-coverage-mapping \ // RUN: -fdiagnostics-color \ // RUN: -fno-diagnostics-color \ // RUN: -fdiagnostics-parseable-fixits \ // RUN: -fdiagnostics-absolute-paths \ // RUN: -ferror-limit=10 \ // RUN: -fmsc-version=1800 \ // RUN: -fno-strict-aliasing \ // RUN: -fstrict-aliasing \ // RUN: -fsyntax-only \ // RUN: -fms-compatibility \ // RUN: -fno-ms-compatibility \ // RUN: -fms-extensions \ // RUN: -fno-ms-extensions \ // RUN: -Xclang -disable-llvm-passes \ // RUN: -resource-dir asdf \ // RUN: -resource-dir=asdf \ // RUN: -Wunused-variable \ // RUN: -fmacro-backtrace-limit=0 \ // RUN: -fstandalone-debug \ // RUN: -flimit-debug-info \ // RUN: -flto \ // RUN: -fmerge-all-constants \ // RUN: -no-canonical-prefixes \ // RUN: -march=skylake \ // RUN: --version \ // RUN: -Werror /Zs -- %s 2>&1 // Accept clang options under the /clang: flag. // The first test case ensures that the SLP vectorizer is on by default and that // it's being turned off by the /clang:-fno-slp-vectorize flag. // RUN: %clang_cl -O2 -### -- %s 2>&1 | FileCheck -check-prefix=NOCLANG %s // NOCLANG: "--dependent-lib=libcmt" // NOCLANG-SAME: "-vectorize-slp" // NOCLANG-NOT: "--dependent-lib=msvcrt" // RUN: %clang_cl -O2 -MD /clang:-fno-slp-vectorize /clang:-MD /clang:-MF /clang:my_dependency_file.dep -### -- %s 2>&1 | FileCheck -check-prefix=CLANG %s // CLANG: "--dependent-lib=msvcrt" // CLANG-SAME: "-dependency-file" "my_dependency_file.dep" // CLANG-NOT: "--dependent-lib=libcmt" // CLANG-NOT: "-vectorize-slp" void f() { }
the_stack_data/148577386.c
#include <stdio.h> float avg(void); // function prototype int main() { printf("%f", avg()); return 0; } float avg(void) { float sum = 0, temp; int t = 10; while (t--) { scanf("%f", &temp); sum += temp; } return sum / 10.0; } // Date: বৃহস্পতিবার, ফেব্রুয়ারী 25, 2021 | 23:42:24
the_stack_data/129751.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <netdb.h> #include <netinet/in.h> void receive(int port); int main(int argc, char **argv) { if(argc != 3){ printf("Invalid ammount of input arguments.\n"); return 1; } if(strcmp(argv[1], "receive") != 0){ printf("Invalid mode (usage: nettd receive [portnr]).\n"); return 1; } if(strcmp(argv[1], "receive") == 0){ receive(atoi(argv[2])); } return 0; } void receive(int port) { int sock, clientsocket, clilen; struct sockaddr_in serv_addr, cli_addr; sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { perror("Could not open socket"); exit(1); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(port); if (bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { perror("Could not bild to port"); exit(1); } listen(sock, 5); clilen = sizeof(cli_addr); int n; clientsocket = accept(sock, (struct sockaddr *)&cli_addr, &clilen); if (clientsocket < 0) { perror("Could not accept client"); exit(1); } char buffer[256]; bzero(buffer, 256); while (n = read(clientsocket, buffer, 255) > 0){ printf("%s", buffer); } }
the_stack_data/190767085.c
/* PR c/82437 */ /* { dg-do compile { target int32plus } } */ /* { dg-options "-Wtautological-compare" } */ int foo (unsigned int x) { if ((x & -1879048192) != -1879048192) /* { dg-bogus "bitwise comparison always evaluates to" } */ return 0; return 1; }
the_stack_data/36074598.c
#include <stdio.h> int main(void) { char name[100]; double buff; //Buffer for fscanf int exit = 0; //for main while loop cutoff int sub_exit = 0; //for sub-while loops cutoff int option; //option int min = 0; const char *items[] = {"Cheese Pizza", "Other", "Books"}; //Abstraction double budget[3] = {-1,-1,-1}; double balance[3] = {0, 0, 0}; double expenses[3] = {0, 0, 0}; double percentage = 0; //Read File FILE *fp; int weeks = 0; fp = fopen("expenses.txt","r"); if (fp == NULL) { printf("The file cannot be found\n"); return -1; } //Print expenses fscanf(fp,"%d", &weeks); for(int i = 0;i < weeks; i++) { for(int j = 0;j < 3; j++){ fscanf(fp, "%lf", &buff); expenses[j] = expenses[j] + buff; } } fclose(fp); /*Average calculation*/ printf("Average expenses:\n"); for(int k = 0;k < weeks; k++) { expenses[k] = expenses[k] / weeks; printf("%14s = %-6.2lf\n", items[k], expenses[k]); } //Name Input printf("\nWhat is your name? "); scanf("%s", name); if(name[0] >= 97 && name[0] <= 122){name[0] = name[0] - 32;} //Budget input menu while(!exit){ option = 0; printf("\nBUDGET:\n1. FOOD\n2. EDUCATION\n3. EXIT\n>"); scanf("%d",&option); switch(option){ case 1: //FOOD do{ sub_exit = 0; printf("\nFOOD:\n1. CHEESE/PIZZA\n2. OTHERS\n3. EXIT\n>"); scanf("%d",&option); switch (option){ case 1: printf("What is your budget for Cheese Pizza? $"); scanf("%lf", &budget[0]); while(budget[0] < 0 ){ printf("You must enter a positive number. $"); scanf("%lf", &budget[0]); } break; case 2: printf("What is your budget for Other itens? "); scanf("%lf", &budget[1]); while(budget[1] < 0){ printf("You must enter a positive value. $"); scanf("%lf", &budget[1]); } break; case 3: if(budget[0] < 0 || budget[1] < 0){ printf("You must input values for both sub-categories"); }else{sub_exit = 1;} break; default: printf("You did not select a valid option"); } }while(!sub_exit); break; case 2: //EDUCATION do{ sub_exit = 0; option = 0; printf("\nEDUCATION:\n1. Books\n2. Back to main menu\n>"); scanf("%d",&option); switch (option){ case 1: printf("What is your budget for Books? $"); scanf("%lf", &budget[2]); while(budget[2] < 0){ printf("You must enter a positive number. $"); scanf("%lf", &budget[2]); } break; case 2: if(budget[2] < 0){ printf("You must input a value for Books\n"); }else{sub_exit = 1;} break; default: printf("You did not select a valid option"); } }while(!sub_exit); break; case 3: //EXIT if(budget[0] < 0 || budget[1] < 0 || budget[2] < 0){ printf("You must input a value for all categories and all sub-categories\n"); }else{exit = 1;} break; default: printf("Invalid menu option\n"); } } //Balance Output printf("\nBalance:\n"); for(int l = 0; l < weeks; l++){ balance[l] = budget[l] - expenses[l]; printf("%14s: %-6.2lf = %-6.2lf - %6.2lf\n", items[l],balance[l],budget[l], expenses[l]); if(balance[l] < 0 && balance[l] <= balance[min]){ min = l; percentage = -(balance[l] / budget[l]); } } //Budget increse ( if(percentage != 0) { printf("\nIncrease budget by %4.2f%%\n\n", percentage * 100); for(int l = 0; l < weeks; l++){ budget[l] = budget[l] * percentage + budget[l]; balance[l] = budget[l] - expenses[l]; printf("%14s: %-6.2lf = %-6.2lf - %6.2lf\n", items[l],balance[l],budget[l], expenses[l]); } } //Write to budget.txt fp = fopen("budgets.txt","w"); if (fp == NULL) { printf("The file, 'expenses.txt' cannot be found or made.\n"); return -1; } fprintf(fp,"Number of weeks: %i\n", weeks); for(int k = 0;k < weeks; k++) { fprintf(fp,"%12s = %-6.2lf\n", items[k], balance[k]); } fclose(fp); return 0; }
the_stack_data/499602.c
extern void abort(void); void reach_error(){} extern void abort(void); void assume_abort_if_not(int cond) { if(!cond) {abort();} } void __VERIFIER_assert(int cond) { if (!(cond)) { ERROR: {reach_error();abort();} } return; } int SIZE = 20000001; int __VERIFIER_nondet_int(); int main() { unsigned int n=0,i=0,k=0,j=0,l=0; unsigned int v1=0, v2=0, v3=0, v4=0, v5=0, v6=0; n = __VERIFIER_nondet_int(); if (!(n <= SIZE)) return 0; while( l < n ) { if(!(l%9)) v6 = v6 + 1; else if(!(l%8)) v5 = v5 + 1; else if(!(l%7)) v1 = v1 + 1; else if(!(l%6)) v2 = v2 + 1; else if(!(l%5)) v3 = v3 + 1; else if(!(l%4)) v4 = v4 + 1; else if(!(l%3)) i = i + 1; else if(!(l%2)) j = j+1; else k = k+1; l = l+1; __VERIFIER_assert((i+j+k+v1+v2+v3+v4+v5+v6) == l); } return 0; }
the_stack_data/137595.c
#include <stdio.h> int main() { int c; printf(" *** Show a number in variety formats. *** \n"); printf("Enter integer : "); scanf("%d", &c); printf("Char -> %c\n", c); printf("Float -> %.2f\n", c * 1.00); printf("Int*2.5 -> %.4f\n", c * 2.5); return 0; }
the_stack_data/18762.c
#include <pthread.h> void* thread(void *arg) { int x; int i; x = rand(); assume(x > 0); i = 0; while (i < x) { i++; } assert(i == x); return NULL; } void main() { pthread_t t; while(rand()){ pthread_create(&t, NULL, thread, NULL); } }
the_stack_data/411906.c
/************************************************************************* * sll.c * * Edward M. Poot * [email protected] * * Hacker 5 * * Implements a simple singly-linked list structure for ints. ************************************************************************/ #include <assert.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> // the size of our test list: feel free to adjust as you wish! #define TEST_SIZE 10 typedef struct node { // the value to store in this node int i; // the link to the next node in the list struct node* next; } node; // declare the first node of our list (as a global variable) node* first = NULL; /** * Returns the length of the list. */ int length(void) { int length = 0; node* ptr = first; while (ptr != NULL) { length++; ptr = ptr->next; } return length; } /** * Returns true if a node in the list contains the value i and false * otherwise. */ bool contains(int i) { node* node = first; int count = 0; while (node != NULL) { if (node->i == count) return true; count++; node = node->next; } return false; } /** * Puts a new node containing i at the front (head) of the list. */ void prepend(int i) { node* temp = (node* ) malloc(sizeof(node)); temp->i = i; temp->next = first; first = temp; } /** * Puts a new node containing i at the end (tail) of the list. */ void append(int i) { node* ptr = first; node* new = (node* ) malloc(sizeof(node)); new->i = i; new->next = NULL; if (first == NULL) { first = new; return; } while (ptr->next != NULL) ptr = ptr->next; ptr->next = new; } /** * Puts a new node containing i at the appropriate position in a list * sorted in ascending order. */ void insert_sorted(int i) { node* ptr = first; node* new = (node *) malloc(sizeof(node)); new->i = i; if (ptr == NULL) { first = new; new->next = NULL; return; } if (ptr->i >= i) { new->next = first; first = new; return; } while(ptr->next != NULL) { if (ptr->next->i >= i) { new->next = ptr->next; ptr->next = new; return; } ptr = ptr->next; } ptr->next = new; new->next = NULL; } /** * Implements some simple test code for our singly-linked list. */ int main(void) { printf("Prepending ints 0-%d onto the list...", TEST_SIZE); for (int i = 0; i < TEST_SIZE; i++) { prepend(i); } printf("done!\n"); printf("Making sure that the list length is indeed %d...", TEST_SIZE); assert(length() == TEST_SIZE); printf("good!\n"); printf("Making sure that values are arranged in descending order..."); node* n = first; for (int i = 0; i < TEST_SIZE; i++) { assert(n != NULL); assert(n->i == TEST_SIZE - i - 1); n = n->next; } printf("good!\n"); printf("Freeing the list..."); while (first != NULL) { node* next = first->next; free(first); first = next; } printf("done!\n"); printf("Appending ints 0-%d to the list...", TEST_SIZE); for (int i = 0; i < TEST_SIZE; i++) { append(i); } printf("done!\n"); printf("Making sure that the list length is indeed %d...", TEST_SIZE); assert(length() == TEST_SIZE); printf("good!\n"); printf("Making sure that values are arranged in ascending order..."); n = first; for (int i = 0; i < TEST_SIZE; i++) { assert(n != NULL); assert(n->i == i); n = n->next; } printf("good!\n"); printf("Freeing the list..."); while (first != NULL) { node* next = first->next; free(first); first = next; } printf("done!\n"); printf("Inserting %d random ints to the list...", TEST_SIZE); for (int i = 0; i < TEST_SIZE; i++) { insert_sorted(rand() % TEST_SIZE); } printf("done!\n"); printf("Making sure that the list length is indeed %d...", TEST_SIZE); assert(length() == TEST_SIZE); printf("good!\n"); printf("Making sure that values are arranged in sorted order..."); n = first; int prev = 0; for (int i = 0; i < TEST_SIZE; i++) { assert(n != NULL); assert(n->i >= prev); prev = n->i; n = n->next; } printf("good!\n"); printf("Freeing the list..."); while (first != NULL) { node* next = first->next; free(first); first = next; } printf("done!\n"); printf("\n********\nSuccess!\n********\n"); return 0; }
the_stack_data/90866.c
/* Test to strtod etc for numbers like x000...0000.000e-nn. This file is part of the GNU C Library. Copyright (C) 2001 Free Software Foundation, Inc. Contributed by Ulrich Drepper <[email protected]>, 2001. 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, see <http://www.gnu.org/licenses/>. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main (void) { char buf[300]; int cnt; int result = 0; for (cnt = 0; cnt < 200; ++cnt) { ssize_t n; float f; n = sprintf (buf, "%d", cnt); memset (buf + n, '0', cnt); sprintf (buf + n + cnt, ".000e-%d", cnt); f = strtof (buf, NULL); if (f != (float) cnt) { printf ("strtof(\"%s\") failed for cnt == %d (%g instead of %g)\n", buf, cnt, f, (float) cnt); result = 1; } else printf ("strtof() fine for cnt == %d\n", cnt); } for (cnt = 0; cnt < 200; ++cnt) { ssize_t n; double f; n = sprintf (buf, "%d", cnt); memset (buf + n, '0', cnt); sprintf (buf + n + cnt, ".000e-%d", cnt); f = strtod (buf, NULL); if (f != (double) cnt) { printf ("strtod(\"%s\") failed for cnt == %d (%g instead of %g)\n", buf, cnt, f, (double) cnt); result = 1; } else printf ("strtod() fine for cnt == %d\n", cnt); } for (cnt = 0; cnt < 200; ++cnt) { ssize_t n; long double f; n = sprintf (buf, "%d", cnt); memset (buf + n, '0', cnt); sprintf (buf + n + cnt, ".000e-%d", cnt); f = strtold (buf, NULL); if (f != (long double) cnt) { printf ("strtold(\"%s\") failed for cnt == %d (%Lg instead of %Lg)\n", buf, cnt, f, (long double) cnt); result = 1; } else printf ("strtold() fine for cnt == %d\n", cnt); } return result; }
the_stack_data/1200463.c
#include <stdint.h> const uint8_t __emoji_u1F60B[4856] = { 0x00, 0x00, 0x00, 0x00, // uint32_t id 0x28, 0x00, 0x00, 0x00, // int32_t width 0x28, 0x00, 0x00, 0x00, // int32_t height 0x08, 0x00, 0x00, 0x00, // ui_pixel_format_t pf 0x38, 0x00, 0x00, 0x00, // uint32_t header_size 0x00, 0x19, 0x00, 0x00, // uint32_t data_size 0x00, 0x00, 0x00, 0x00, // int32_t reserved[0] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[1] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[2] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[3] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[4] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[5] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[6] 0x00, 0x00, 0x00, 0x00, // int32_t reserved[7] 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, 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, 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, 0xf8, 0x00, 0x03, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x89, 0x09, 0xd4, 0x87, 0x1e, 0xe4, 0xa6, 0x2a, 0xe4, 0xa6, 0x2a, 0xdc, 0x87, 0x1e, 0xcc, 0x89, 0x0a, 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, 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, 0xcc, 0x67, 0x0a, 0xec, 0xa4, 0x51, 0xf5, 0x03, 0x9b, 0xfd, 0x63, 0xd5, 0xfd, 0xa3, 0xf6, 0xfd, 0xc3, 0xff, 0xfe, 0x03, 0xff, 0xfe, 0x03, 0xff, 0xfd, 0xc3, 0xff, 0xfd, 0xa3, 0xf7, 0xfd, 0x43, 0xd7, 0xf5, 0x03, 0x9d, 0xec, 0xa3, 0x54, 0xd4, 0x46, 0x0c, 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, 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, 0xdc, 0x44, 0x1a, 0xf4, 0xc2, 0x8b, 0xfd, 0x42, 0xed, 0xfd, 0xe2, 0xff, 0xfe, 0x62, 0xff, 0xfe, 0xc4, 0xff, 0xff, 0x28, 0xff, 0xff, 0x6b, 0xff, 0xff, 0x6d, 0xff, 0xff, 0x6d, 0xff, 0xff, 0x6c, 0xff, 0xff, 0x28, 0xff, 0xfe, 0xc4, 0xff, 0xfe, 0x62, 0xff, 0xfd, 0xe2, 0xff, 0xfd, 0x42, 0xef, 0xf4, 0xc2, 0x90, 0xdc, 0x44, 0x1d, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x26, 0x06, 0xf4, 0x82, 0x7b, 0xfd, 0x21, 0xf3, 0xfd, 0xe1, 0xff, 0xfe, 0x83, 0xff, 0xff, 0x4c, 0xff, 0xff, 0xb5, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xd6, 0xff, 0xff, 0x4e, 0xff, 0xfe, 0xa4, 0xff, 0xfd, 0xe1, 0xff, 0xfd, 0x21, 0xf5, 0xf4, 0x82, 0x82, 0xc4, 0x26, 0x08, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x23, 0x23, 0xf4, 0xa1, 0xcc, 0xfd, 0x81, 0xff, 0xfe, 0x42, 0xff, 0xff, 0x4e, 0xff, 0xff, 0xd8, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0x6f, 0xff, 0xfe, 0x63, 0xff, 0xfd, 0x81, 0xff, 0xfc, 0xa1, 0xd1, 0xe4, 0x23, 0x28, 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, 0xe4, 0x22, 0x3a, 0xfc, 0xc1, 0xeb, 0xfd, 0xa1, 0xff, 0xfe, 0xa7, 0xff, 0xff, 0xb5, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xfa, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd6, 0xff, 0xfe, 0xc9, 0xff, 0xfd, 0xc1, 0xff, 0xfc, 0xc1, 0xee, 0xe4, 0x22, 0x41, 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, 0xe4, 0x02, 0x3a, 0xfc, 0xc0, 0xf2, 0xfd, 0xa1, 0xff, 0xfe, 0xea, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xd8, 0xff, 0xff, 0xd8, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd7, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0x0d, 0xff, 0xfd, 0xc1, 0xff, 0xfc, 0xc0, 0xf6, 0xe4, 0x22, 0x41, 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, 0xdb, 0xe3, 0x23, 0xfc, 0x80, 0xeb, 0xfd, 0x81, 0xff, 0xfe, 0xca, 0xff, 0xff, 0x93, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd6, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd5, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd3, 0xff, 0xff, 0x93, 0xff, 0xfe, 0xed, 0xff, 0xfd, 0xa1, 0xff, 0xfc, 0xa0, 0xef, 0xdc, 0x03, 0x29, 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, 0xbb, 0xe7, 0x06, 0xf4, 0x41, 0xcc, 0xfd, 0x40, 0xff, 0xfe, 0x67, 0xff, 0xff, 0x71, 0xff, 0xff, 0x91, 0xff, 0xff, 0xb1, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd4, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xb1, 0xff, 0xff, 0x91, 0xff, 0xff, 0x51, 0xff, 0xfe, 0xaa, 0xff, 0xfd, 0x60, 0xff, 0xf4, 0x61, 0xd3, 0xc3, 0xe6, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x01, 0x7b, 0xfc, 0xe0, 0xff, 0xfd, 0xe4, 0xff, 0xff, 0x0e, 0xff, 0xff, 0x4f, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xb0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd2, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd1, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xb0, 0xff, 0xff, 0xaf, 0xff, 0xff, 0x6f, 0xff, 0xff, 0x4f, 0xff, 0xff, 0x0e, 0xff, 0xfe, 0x25, 0xff, 0xfc, 0xe0, 0xff, 0xec, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0xc4, 0x1a, 0xf4, 0x60, 0xf4, 0xfd, 0x61, 0xff, 0xfe, 0xaa, 0xff, 0xff, 0x0d, 0xff, 0xff, 0x2d, 0xff, 0xff, 0x6d, 0xff, 0xff, 0x8e, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0x8e, 0xff, 0xff, 0x6d, 0xff, 0xff, 0x4d, 0xff, 0xff, 0x0d, 0xff, 0xfe, 0xcc, 0xff, 0xfd, 0x61, 0xff, 0xfc, 0x60, 0xf7, 0xd3, 0xe3, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe1, 0x8b, 0xfc, 0xc0, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0xcb, 0xff, 0xfe, 0xeb, 0xff, 0xff, 0x2b, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x6c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xac, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xae, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0xad, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x6c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x2b, 0xff, 0xfe, 0xeb, 0xff, 0xfe, 0xcb, 0xff, 0xfe, 0x06, 0xff, 0xfc, 0xe0, 0xff, 0xec, 0x01, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xe6, 0x0a, 0xec, 0x20, 0xed, 0xfd, 0x21, 0xff, 0xfe, 0x48, 0xff, 0xfe, 0xa9, 0xff, 0xfe, 0xca, 0xff, 0xff, 0x0a, 0xff, 0xff, 0x2a, 0xff, 0xff, 0x4a, 0xff, 0xff, 0x6b, 0xff, 0xff, 0x2a, 0xff, 0xd5, 0xc7, 0xff, 0xe6, 0x48, 0xff, 0xff, 0x8b, 0xff, 0xff, 0xab, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xac, 0xff, 0xff, 0xab, 0xff, 0xff, 0x6a, 0xff, 0xd5, 0xc7, 0xff, 0xe6, 0x28, 0xff, 0xff, 0x6a, 0xff, 0xff, 0x6b, 0xff, 0xff, 0x4a, 0xff, 0xff, 0x2a, 0xff, 0xff, 0x0a, 0xff, 0xfe, 0xca, 0xff, 0xfe, 0xa9, 0xff, 0xfe, 0x48, 0xff, 0xfd, 0x21, 0xff, 0xf4, 0x20, 0xf2, 0xc3, 0xe6, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0xc2, 0x50, 0xf4, 0x60, 0xff, 0xfd, 0x62, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x88, 0xff, 0xfe, 0xa8, 0xff, 0xfe, 0xe9, 0xff, 0xff, 0x09, 0xff, 0xff, 0x29, 0xff, 0xff, 0x09, 0xff, 0x93, 0x22, 0xff, 0x69, 0xc0, 0xff, 0x69, 0xc0, 0xff, 0xc4, 0xe5, 0xff, 0xff, 0x8a, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0xaa, 0xff, 0xff, 0x69, 0xff, 0x9b, 0x62, 0xff, 0x69, 0xc0, 0xff, 0x69, 0xc0, 0xff, 0xc4, 0xc4, 0xff, 0xff, 0x29, 0xff, 0xff, 0x29, 0xff, 0xff, 0x09, 0xff, 0xfe, 0xe9, 0xff, 0xfe, 0xa8, 0xff, 0xfe, 0x88, 0xff, 0xfe, 0x47, 0xff, 0xfd, 0x83, 0xff, 0xf4, 0x80, 0xff, 0xdb, 0xc2, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xc1, 0x99, 0xf4, 0xa0, 0xff, 0xfd, 0x84, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x87, 0xff, 0xfe, 0xc7, 0xff, 0xfe, 0xe8, 0xff, 0xff, 0x08, 0xff, 0xc4, 0xe4, 0xff, 0x82, 0x20, 0xff, 0x9a, 0xe0, 0xff, 0x92, 0xc0, 0xff, 0x7a, 0x20, 0xff, 0xf6, 0xc7, 0xff, 0xff, 0x69, 0xff, 0xff, 0x89, 0xff, 0xff, 0x88, 0xff, 0xff, 0x88, 0xff, 0xff, 0x89, 0xff, 0xff, 0x68, 0xff, 0xcd, 0x45, 0xff, 0x7a, 0x20, 0xff, 0x9a, 0xe0, 0xff, 0x92, 0xc0, 0xff, 0x7a, 0x20, 0xff, 0xee, 0x66, 0xff, 0xff, 0x08, 0xff, 0xfe, 0xe8, 0xff, 0xfe, 0xc7, 0xff, 0xfe, 0x87, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x26, 0xff, 0xfd, 0xa4, 0xff, 0xf4, 0xa0, 0xff, 0xe3, 0xe1, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe1, 0xd4, 0xf4, 0xa0, 0xff, 0xfd, 0x84, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xc7, 0xff, 0xfe, 0xe7, 0xff, 0x9b, 0x22, 0xff, 0x92, 0xc0, 0xff, 0xa3, 0x00, 0xff, 0xa3, 0x00, 0xff, 0x8a, 0x80, 0xff, 0xcd, 0x04, 0xff, 0xff, 0x47, 0xff, 0xff, 0x47, 0xff, 0xff, 0x67, 0xff, 0xff, 0x67, 0xff, 0xff, 0x67, 0xff, 0xff, 0x47, 0xff, 0xa3, 0x82, 0xff, 0x92, 0xc0, 0xff, 0xa3, 0x00, 0xff, 0xa3, 0x00, 0xff, 0x8a, 0x80, 0xff, 0xc4, 0x83, 0xff, 0xfe, 0xe7, 0xff, 0xfe, 0xc7, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x05, 0xff, 0xfd, 0xa4, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe1, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0xe8, 0x08, 0xe3, 0xe0, 0xf6, 0xf4, 0xc1, 0xff, 0xfd, 0x83, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0x8a, 0x81, 0xff, 0x9b, 0x21, 0xff, 0xd5, 0xa5, 0xff, 0xbc, 0xc4, 0xff, 0x8a, 0x80, 0xff, 0xb4, 0x43, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0xff, 0x26, 0xff, 0x92, 0xc1, 0xff, 0x9b, 0x01, 0xff, 0xd5, 0x85, 0xff, 0xc5, 0x25, 0xff, 0x92, 0xa0, 0xff, 0xab, 0xc2, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x25, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0x84, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe0, 0xfb, 0xbb, 0xe7, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xa5, 0x1d, 0xe3, 0xe0, 0xff, 0xf4, 0xc1, 0xff, 0xfd, 0x63, 0xff, 0xfd, 0xc4, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x85, 0xff, 0x82, 0x40, 0xff, 0xee, 0x66, 0xff, 0xfe, 0xe5, 0xff, 0xff, 0x26, 0xff, 0xb4, 0x43, 0xff, 0xb4, 0x22, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0x8a, 0x81, 0xff, 0xde, 0x05, 0xff, 0xfe, 0xe5, 0xff, 0xfe, 0xe6, 0xff, 0xc4, 0xc4, 0xff, 0xab, 0xa2, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x05, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x83, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe0, 0xff, 0xbb, 0xa4, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x84, 0x28, 0xdb, 0xc0, 0xff, 0xf4, 0xc1, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x25, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0xa5, 0xff, 0xcd, 0x45, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xf6, 0xa6, 0xff, 0xd5, 0xc5, 0xff, 0xfe, 0xe6, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xff, 0x06, 0xff, 0xd5, 0xc5, 0xff, 0xff, 0x06, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc5, 0xff, 0xf6, 0x85, 0xff, 0xd5, 0x85, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x25, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x62, 0xff, 0xf4, 0xc1, 0xff, 0xe3, 0xe0, 0xff, 0xc3, 0x83, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x84, 0x29, 0xdb, 0xc0, 0xff, 0xec, 0xa0, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0xe5, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xe6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0xa5, 0xff, 0xfe, 0x85, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x25, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0x42, 0xff, 0xec, 0xa1, 0xff, 0xdb, 0xe0, 0xff, 0xc3, 0x63, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0x85, 0x1d, 0xdb, 0xa0, 0xff, 0xec, 0x80, 0xff, 0xf5, 0x21, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0xc5, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x65, 0xff, 0xfe, 0x45, 0xff, 0xfe, 0x05, 0xff, 0xfe, 0x05, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xa3, 0xff, 0xf5, 0x21, 0xff, 0xec, 0xa1, 0xff, 0xdb, 0xc0, 0xff, 0xbb, 0x84, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0xe7, 0x09, 0xd3, 0x80, 0xf6, 0xe4, 0x60, 0xff, 0xf5, 0x01, 0xff, 0xfd, 0x82, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0xc5, 0xff, 0x8a, 0x81, 0xff, 0xdc, 0xe4, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xc6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xbb, 0xe2, 0xff, 0xb3, 0x82, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x83, 0xff, 0xf5, 0x21, 0xff, 0xe4, 0x61, 0xff, 0xd3, 0xa0, 0xfb, 0xb3, 0xc6, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x81, 0xd5, 0xe4, 0x40, 0xff, 0xec, 0xe1, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0xe5, 0xff, 0x7a, 0x00, 0xff, 0x9b, 0x02, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0xa6, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xf5, 0xe5, 0xff, 0xa1, 0x86, 0xff, 0xb2, 0x85, 0xff, 0xfd, 0xe5, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0x62, 0xff, 0xf4, 0xe1, 0xff, 0xe4, 0x40, 0xff, 0xcb, 0x81, 0xdf, 0xb3, 0xe7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x61, 0x9b, 0xdc, 0x00, 0xff, 0xec, 0xa1, 0xff, 0xf5, 0x22, 0xff, 0xfd, 0x83, 0xff, 0xfd, 0xc4, 0xff, 0xa3, 0x62, 0xff, 0x7a, 0x20, 0xff, 0xf5, 0x85, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x86, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xd4, 0x44, 0xff, 0xd1, 0x6b, 0xff, 0xf1, 0xaf, 0xff, 0xea, 0xca, 0xff, 0xfd, 0x43, 0xff, 0xf5, 0x22, 0xff, 0xec, 0xc1, 0xff, 0xdc, 0x00, 0xff, 0xcb, 0x61, 0xa5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x42, 0x52, 0xd3, 0xa0, 0xff, 0xe4, 0x61, 0xff, 0xf5, 0x01, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0x83, 0xff, 0xdd, 0x04, 0xff, 0x82, 0x40, 0xff, 0xab, 0x82, 0xff, 0xfe, 0x06, 0xff, 0xfe, 0x26, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x66, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x46, 0xff, 0xfe, 0x26, 0xff, 0xfd, 0xe6, 0xff, 0xaa, 0x45, 0xff, 0xf2, 0x10, 0xff, 0xfa, 0x93, 0xff, 0xfa, 0xb3, 0xff, 0xea, 0x2d, 0xff, 0xec, 0x83, 0xff, 0xe4, 0x81, 0xff, 0xd3, 0xc0, 0xff, 0xc3, 0x42, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0xc6, 0x0b, 0xcb, 0x60, 0xee, 0xdc, 0x20, 0xff, 0xec, 0xc1, 0xff, 0xf5, 0x22, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xc4, 0xff, 0xa3, 0x42, 0xff, 0x7a, 0x20, 0xff, 0xe4, 0xe4, 0xff, 0xfe, 0x06, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x67, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x06, 0xff, 0xc3, 0xc4, 0xff, 0xc1, 0xeb, 0xff, 0xfa, 0x72, 0xff, 0xfa, 0xf4, 0xff, 0xfb, 0x96, 0xff, 0xfb, 0x96, 0xff, 0xea, 0x6e, 0xff, 0xdb, 0xe2, 0xff, 0xcb, 0x60, 0xf3, 0xb3, 0xa5, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x41, 0x8e, 0xd3, 0xc0, 0xff, 0xe4, 0x61, 0xff, 0xec, 0xe2, 0xff, 0xf5, 0x42, 0xff, 0xfd, 0x62, 0xff, 0xf5, 0xa4, 0xff, 0x8a, 0x81, 0xff, 0x82, 0x41, 0xff, 0xf5, 0x65, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x47, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x06, 0xff, 0xdc, 0x84, 0xff, 0xb9, 0xe8, 0xff, 0xf2, 0x72, 0xff, 0xea, 0x72, 0xff, 0xfb, 0x14, 0xff, 0xfb, 0xd7, 0xff, 0xfc, 0x38, 0xff, 0xfb, 0x35, 0xff, 0xd2, 0x27, 0xff, 0xcb, 0x41, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x64, 0x1c, 0xcb, 0x60, 0xf5, 0xdc, 0x01, 0xff, 0xe4, 0xa1, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x42, 0xff, 0xfd, 0x82, 0xff, 0xe5, 0x64, 0xff, 0x82, 0x61, 0xff, 0x8a, 0x61, 0xff, 0xed, 0x25, 0xff, 0xfd, 0xe7, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x27, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfd, 0xe6, 0xff, 0xd4, 0x64, 0xff, 0xa9, 0xa6, 0xff, 0xf2, 0x30, 0xff, 0xfa, 0xd4, 0xff, 0xfb, 0x35, 0xff, 0xfb, 0x75, 0xff, 0xfc, 0x18, 0xff, 0xfc, 0x18, 0xff, 0xfb, 0x15, 0xff, 0xd1, 0x8a, 0xf8, 0xc3, 0x62, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x41, 0x80, 0xd3, 0xa0, 0xff, 0xdc, 0x41, 0xff, 0xe4, 0xc2, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x42, 0xff, 0xfd, 0x63, 0xff, 0xed, 0x84, 0xff, 0x93, 0x02, 0xff, 0x79, 0xe0, 0xff, 0xcc, 0x43, 0xff, 0xfd, 0xa5, 0xff, 0xfd, 0xe6, 0xff, 0xfd, 0xe7, 0xff, 0xfd, 0xe7, 0xff, 0xfe, 0x07, 0xff, 0xfe, 0x07, 0xff, 0xfd, 0xe7, 0xff, 0xfd, 0xe7, 0xff, 0xfd, 0xe6, 0xff, 0xfd, 0x85, 0xff, 0xb3, 0x82, 0xff, 0x71, 0xc0, 0xff, 0xba, 0x86, 0xff, 0xf1, 0xd0, 0xff, 0xfb, 0x15, 0xff, 0xfb, 0xb7, 0xff, 0xfc, 0x18, 0xff, 0xfc, 0x38, 0xff, 0xfb, 0x96, 0xff, 0xfa, 0x72, 0xff, 0xc0, 0xeb, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x03, 0x08, 0xcb, 0x40, 0xd0, 0xd3, 0xc0, 0xff, 0xdc, 0x41, 0xff, 0xec, 0xc2, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x42, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0xc4, 0xff, 0xc4, 0xa4, 0xff, 0x7a, 0x41, 0xff, 0x8a, 0x61, 0xff, 0xcc, 0x03, 0xff, 0xf5, 0x44, 0xff, 0xfd, 0xa5, 0xff, 0xfd, 0xc5, 0xff, 0xfd, 0xa5, 0xff, 0xfd, 0x85, 0xff, 0xed, 0x04, 0xff, 0xbb, 0xa2, 0xff, 0x7a, 0x00, 0xff, 0x8a, 0xe2, 0xff, 0xdd, 0x44, 0xff, 0xfd, 0x63, 0xff, 0xe3, 0x65, 0xff, 0xf2, 0x0f, 0xff, 0xfb, 0xb6, 0xff, 0xfc, 0x18, 0xff, 0xfb, 0x96, 0xff, 0xfa, 0xb3, 0xff, 0xd9, 0x2d, 0xf8, 0xa0, 0xe8, 0x2d, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xc3, 0x62, 0x27, 0xcb, 0x60, 0xee, 0xd3, 0xe0, 0xff, 0xdc, 0x61, 0xff, 0xe4, 0xa2, 0xff, 0xed, 0x02, 0xff, 0xf5, 0x22, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x63, 0xff, 0xfd, 0xc4, 0xff, 0xdd, 0x04, 0xff, 0xa3, 0xc3, 0xff, 0x8a, 0xc2, 0xff, 0x8a, 0x81, 0xff, 0x92, 0x81, 0xff, 0x92, 0x81, 0xff, 0x8a, 0xa1, 0xff, 0x93, 0x02, 0xff, 0xb4, 0x23, 0xff, 0xe5, 0x64, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0x42, 0xff, 0xf4, 0xc2, 0xff, 0xe3, 0xa2, 0xff, 0xe2, 0x8b, 0xff, 0xf2, 0x31, 0xff, 0xf1, 0xf1, 0xff, 0xd1, 0x2c, 0xf3, 0xa8, 0xc9, 0x4d, 0xfd, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xc3, 0x61, 0x3f, 0xcb, 0x60, 0xf5, 0xd3, 0xe0, 0xff, 0xdc, 0x41, 0xff, 0xe4, 0xa2, 0xff, 0xec, 0xe2, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x22, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x63, 0xff, 0xfd, 0xa3, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0xe4, 0xff, 0xfd, 0xe4, 0xff, 0xfd, 0xc4, 0xff, 0xfd, 0x83, 0xff, 0xfd, 0x62, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xf5, 0x22, 0xff, 0xf5, 0x02, 0xff, 0xec, 0xe2, 0xff, 0xdc, 0x21, 0xff, 0xdc, 0x01, 0xff, 0xd3, 0x82, 0xff, 0xc2, 0xe2, 0xf8, 0xbb, 0x22, 0x47, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x01, 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, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xc3, 0x41, 0x40, 0xcb, 0x60, 0xee, 0xd3, 0xc0, 0xff, 0xdc, 0x21, 0xff, 0xe4, 0x81, 0xff, 0xec, 0xc2, 0xff, 0xec, 0xe2, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x22, 0xff, 0xfd, 0x22, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x42, 0xff, 0xfd, 0x22, 0xff, 0xf5, 0x22, 0xff, 0xf5, 0x02, 0xff, 0xec, 0xe2, 0xff, 0xec, 0xc2, 0xff, 0xe4, 0x81, 0xff, 0xdc, 0x21, 0xff, 0xd3, 0xc0, 0xff, 0xcb, 0x60, 0xf1, 0xc3, 0x61, 0x47, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x01, 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, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x03, 0xc3, 0x62, 0x28, 0xc3, 0x40, 0xd1, 0xd3, 0xa0, 0xff, 0xdc, 0x01, 0xff, 0xe4, 0x41, 0xff, 0xe4, 0x81, 0xff, 0xec, 0xc2, 0xff, 0xec, 0xe2, 0xff, 0xf4, 0xe2, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x02, 0xff, 0xf5, 0x02, 0xff, 0xf4, 0xe2, 0xff, 0xec, 0xe2, 0xff, 0xec, 0xc2, 0xff, 0xe4, 0x81, 0xff, 0xe4, 0x61, 0xff, 0xdc, 0x01, 0xff, 0xd3, 0xa0, 0xff, 0xcb, 0x40, 0xd6, 0xc3, 0x62, 0x2e, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 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, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x03, 0xdc, 0x42, 0x0b, 0xc3, 0x41, 0x82, 0xcb, 0x60, 0xf5, 0xd3, 0xc0, 0xff, 0xdc, 0x01, 0xff, 0xdc, 0x41, 0xff, 0xe4, 0x61, 0xff, 0xe4, 0x81, 0xff, 0xec, 0xa1, 0xff, 0xec, 0xa1, 0xff, 0xec, 0xc1, 0xff, 0xec, 0xc1, 0xff, 0xec, 0xa2, 0xff, 0xec, 0xa1, 0xff, 0xe4, 0x81, 0xff, 0xe4, 0x61, 0xff, 0xe4, 0x41, 0xff, 0xdc, 0x01, 0xff, 0xd3, 0xc0, 0xff, 0xcb, 0x60, 0xf7, 0xc3, 0x41, 0x88, 0xdc, 0x22, 0x0d, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 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, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x03, 0xcb, 0xa2, 0x20, 0xc3, 0x21, 0x91, 0xc3, 0x40, 0xf0, 0xd3, 0x80, 0xff, 0xd3, 0xc0, 0xff, 0xdc, 0x01, 0xff, 0xdc, 0x21, 0xff, 0xdc, 0x21, 0xff, 0xdc, 0x41, 0xff, 0xdc, 0x41, 0xff, 0xdc, 0x21, 0xff, 0xdc, 0x21, 0xff, 0xdc, 0x01, 0xff, 0xd3, 0xe0, 0xff, 0xd3, 0xa0, 0xff, 0xcb, 0x40, 0xf2, 0xc3, 0x41, 0x96, 0xc3, 0x82, 0x23, 0xfd, 0x00, 0x04, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x01, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x03, 0xdc, 0x22, 0x0f, 0xbb, 0x41, 0x57, 0xc3, 0x21, 0x9f, 0xc3, 0x40, 0xd9, 0xc3, 0x40, 0xf8, 0xcb, 0x60, 0xff, 0xcb, 0x60, 0xff, 0xcb, 0x60, 0xff, 0xcb, 0x60, 0xff, 0xc3, 0x40, 0xf9, 0xc3, 0x40, 0xdb, 0xc3, 0x20, 0xa2, 0xbb, 0x21, 0x5a, 0xd4, 0x22, 0x10, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xe4, 0x82, 0x0f, 0xc3, 0xc3, 0x23, 0xbb, 0x82, 0x30, 0xbb, 0x82, 0x31, 0xc3, 0xc3, 0x24, 0xe4, 0x82, 0x10, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x04, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 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, 0xf8, 0x00, 0x03, 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, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x03, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x02, 0xfd, 0x00, 0x01, 0xfd, 0x00, 0x01, 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/36075610.c
#include <stdlib.h> #include <stdbool.h> extern bool __VERIFIER_nondet_bool(); int main() { bool selector = __VERIFIER_nondet_bool(); int *ptr = NULL; if (!selector) { ptr = malloc(sizeof(int)); } if (selector) { *ptr = 666; } free(ptr); return 0; }
the_stack_data/98574067.c
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> void dump(int *arr, int size) { int idx; for (idx = 0; idx < size; idx++) printf("%08d\n", arr[idx]); } void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } int partition(int *arr, int p, int r) { //int pivot = arr[r]; int i, j; i = j = p; for (; j < r; j++) { if (arr[j] < arr[r]) { if(i != j) { swap(arr + i, arr + j); } i++; } } swap(arr + i, arr + r); return i; } void __quick_sort(int *arr, int p, int r) { int q; if (p >= r) return; q = partition(arr, p, r); __quick_sort(arr, p, q-1); __quick_sort(arr, q+1, r); } void quick_sort(int *arr, int size) { __quick_sort(arr, 0, size - 1); } void quick_sort_test() { int test[10] = {5, 8, 9, 23, 67, 1, 3, 7, 31, 56}; quick_sort(test, 10); dump(test, 10); } int main() { quick_sort_test(); return 0; }
the_stack_data/28262050.c
/* BEGIN_ICS_COPYRIGHT7 **************************************** Copyright (c) 2015, Intel Corporation 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 Intel Corporation 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. ** END_ICS_COPYRIGHT7 ****************************************/ /* [ICS VERSION STRING: unknown] */ static char *buildVersion = "BUILD_VERSION = DEVELOPMENT (build)"; char *___GetBuildVersion(void) { return buildVersion; }
the_stack_data/730163.c
#include<stdio.h> #include<stdlib.h> #include<sys/wait.h> #include<unistd.h> int main() { pid_t cpid; if (fork()== 0) exit(0); /* terminate child */ else cpid = wait(NULL); /* reaping parent */ printf("Parent pid = %d\n", getpid()); printf("Child pid = %d\n", cpid); return 0; }
the_stack_data/14201384.c
/*numPass=2, numTotal=8 Verdict:ACCEPTED, Visibility:1, Input:"codingisfun i 2 true", ExpOutput:"NO ", Output:"NO" Verdict:WRONG_ANSWER, Visibility:1, Input:"codingisfun c 3 fun", ExpOutput:"NO ", Output:"YES" Verdict:WRONG_ANSWER, Visibility:1, Input:"code o 0 o ", ExpOutput:"YES ", Output:"NO" Verdict:WRONG_ANSWER, Visibility:0, Input:"oo o 0 o ", ExpOutput:"YES ", Output:"NO" Verdict:WRONG_ANSWER, Visibility:0, Input:"oo o 2 o ", ExpOutput:"YES ", Output:"NO" Verdict:WRONG_ANSWER, Visibility:0, Input:"atestcasemanually a 4 ll ", ExpOutput:"YES ", Output:"NO" Verdict:WRONG_ANSWER, Visibility:0, Input:"atestcasemanually a 5 ll ", ExpOutput:"NO ", Output:"YES" Verdict:ACCEPTED, Visibility:0, Input:"atestcasemanually a 4 atestcasemanually", ExpOutput:"YES ", Output:"YES" */ #include <stdio.h> int count_char(char s[],char a){ int count=0,i=0; while((s[i]!='\0')){ if(s[i]==a){ count++; } i++; } return count; } int check_substring(char s1[],char s2[]){ int i,j=0,check; for(i=0;s1[i]!='\0';){ if(s2[j]==s1[i]){ check=1; ++i; ++j; continue; } else{ check=0; break; } } return check; } int main() { int n,count,check=0; char c,s1[100],s2[100]; scanf("%s\n",s1); scanf("%c %d\n",&c,&n); scanf("%s",s2); count=count_char(s1,c); if(count<n){ check++; } check=check+check_substring(s1,s2); if(check==1){ printf("YES"); } else{ printf("NO"); } return 0; }
the_stack_data/1040631.c
/*-----------------------------------------------------------------------------* * Project: SimplePrograms * File: stringfunctions.c * Author: Sanjay Vyas * * Description: * * Revision History: * 2019-August-16: Initial Creation * * Copyright (c) 2019 Sanjay Vyas * * License: * This code is meant for learning algorithms and wrting clean coding * Do not copy-paste it, it may not help in understanding the code * You are required to understand the code and then type it yourself * * Disclaimer: * This code may contain intentional and unintentional bugs * There are no warranties of the code working correctly *----------------------------------------------------------------------------*/ #include <stdio.h> // We are not using <string.h> as we are writing our own /** * strlen takes a const char * parameter because it only counts char * It does not have to modify the original string */ int mystrlen(const char *string) { int count = 0; // Keep counting characters until we hit null terminator while (*string!='\0') // or just write ( *string ) { count++; // count the char string++; // goto next char } return count; } /** * strcmp compares both strings char by char and does not modify them * hence, both param are const char * instead of char * * * strcmp returns * 0 - if it reaches null terminator in both strings, meaning they are exact * <1 - if char in first string is smaller than second at same poisition * >1 - if char in first string is bigger than second at same position */ int mystrcmp(const char *first, const char *second) { // Check both string if either has reached null terminator // and if both char are same, increment addresses of both while (*first && *second && *first == *second) { first++; second++; } // We have come out of the loop because of any of these 3 condition // Either *first == '\0' // or *second == '\0' // or *fist (char first is pointing to ) is not the same as // *second (char second is pointing to) return *first - *second; // Interesting code above, it returns // 0 - if both are '\0' ( '\0' - '\0' is ;9) // <1 - if *first is lesser than *second ( 'a' - 'b == -1) // >1 - if *first is more than *second ('z' - 'y') == +1) // If one of the string has reached null other hasn't, it still works // because '\0' - 'a' == -97 which is < 1 // and 'z' - '\0' == +122 which is > 1 } /** * strcpy takes char * as first param because it will copy there * and const char * as second param because it will just read that string */ char *mystrcpy(char *target, const char * source) { // We will increment target so will lose the original adddress of target // So we need to keep original address which we have to return back char *original = target; // copy char from source to target until we reach null terminator while (*source) { // copy the charcater *target = *source; // move target and source to next target++; source++; } // target is incremented to end of the string, so return original return original; } /** * strcat copies char from source string at the end of target string * it copies characters beyond null terminator * However, it does not (and cannot) increase memory allocation after target * So, if you don't have enough space after target, it will crash or overwrite */ char *mystrcat(char *target, const char *source) { // We have to return address of target, but target will be incremented // So capture the original address of target char *original = target; // First move the target to null terminator // We will start copying char from source to target starting with '\0' while (*target) target++; // Now target is pointing to its null terminator // So start copying source char to target while (*source) { // Copy the char *target = *source; // Increment target and source target++; source++; } // We have copied all chat from source to end of target // But we have not put the null terminator *target = '\0'; // Now return the original return original; } int main() { char fullname[100]; char firstname[50]; char lastname[50]; int len; int cmp; printf("Enter your first name: "); // We dont need & before firstname as // firstname is an array, so its already an address // scanf needs address and not & scanf("%s", firstname); len = mystrlen(firstname); printf("Your firstname (%s) id %d characters long\n", firstname, len); printf("Enter your last name: "); scanf("%s", lastname); len = mystrlen(lastname); printf("Your lastname (%s) id %d characters long\n", firstname, len); cmp = mystrcmp(firstname, lastname); if ( cmp > 0) printf("Your firstname (%s) is greater than your lastname (%s)\n", firstname, lastname); else if (cmp < 0) printf("Your lastname (%s) is greater than your firstname (%s)\n", lastname, firstname); else printf("Wow! your firstname (%s) and lastname (%s) are the same\n", firstname, lastname); // Concatenate first and last name into fullname // first copy firstname into fullname mystrcpy(fullname, firstname); // Now concatenate latename into full name mystrcat(fullname, lastname); printf("Your fullname is %s\n", fullname); return 0; }
the_stack_data/212644509.c
#line 3 "lex.yy.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 #define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ #include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> /* end standard C headers. */ /* flex integer type definitions */ #ifndef FLEXINT_H #define FLEXINT_H /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 #endif #include <inttypes.h> typedef int8_t flex_int8_t; typedef uint8_t flex_uint8_t; typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; #endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN #define INT8_MIN (-128) #endif #ifndef INT16_MIN #define INT16_MIN (-32767-1) #endif #ifndef INT32_MIN #define INT32_MIN (-2147483647-1) #endif #ifndef INT8_MAX #define INT8_MAX (127) #endif #ifndef INT16_MAX #define INT16_MAX (32767) #endif #ifndef INT32_MAX #define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX #define UINT8_MAX (255U) #endif #ifndef UINT16_MAX #define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX #define UINT32_MAX (4294967295U) #endif #endif /* ! FLEXINT_H */ #ifdef __cplusplus /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST #else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ #if defined (__STDC__) #define YY_USE_CONST #endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const #else #define yyconst #endif /* Returned upon end-of-file. */ #define YY_NULL 0 /* Promotes a possibly negative, possibly signed char to an unsigned * integer for use as an array index. If the signed char is negative, * we want to instead treat it as an 8-bit unsigned char, hence the * double cast. */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ #define BEGIN (yy_start) = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ #define YY_NEW_FILE yyrestart(yyin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #ifndef YY_BUF_SIZE #define YY_BUF_SIZE 16384 #endif /* The state buf must be large enough to hold one state per character in the main buffer. */ #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T typedef size_t yy_size_t; #endif extern yy_size_t yyleng; extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 #define YY_LESS_LINENO(n) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ *yy_cp = (yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) #define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state { FILE *yy_input_file; char *yy_ch_buf; /* input buffer */ char *yy_buf_pos; /* current position in input buffer */ /* Size of input buffer in bytes, not including room for EOB * characters. */ yy_size_t yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to * delete it. */ int yy_is_our_buffer; /* Whether this is an "interactive" input source; if so, and * if we're using stdio for input, then we want to use getc() * instead of fread(), to make sure we stop fetching input after * each newline. */ int yy_is_interactive; /* Whether we're considered to be at the beginning of a line. * If so, '^' rules will be active on the next match, otherwise * not. */ int yy_at_bol; int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ /* Whether to try to fill the input buffer when we reach the * end of it. */ int yy_fill_buffer; int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 /* When an EOF's been seen but there's still some text to process * then we mark the buffer as YY_EOF_PENDING, to indicate that we * shouldn't try reading from the input source any more. We might * still have a bunch of tokens to match, though, because of * possible backing-up. * * When we actually see the EOF, we change the status to "new" * (via yyrestart()), so that the user can continue scanning by * just pointing yyin at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ yy_size_t yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches * instead of setting up a fresh yyin. A bit of a hack ... */ static int yy_did_buffer_switch_on_eof; void yyrestart (FILE *input_file ); void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); void yy_delete_buffer (YY_BUFFER_STATE b ); void yy_flush_buffer (YY_BUFFER_STATE b ); void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); void yypop_buffer_state (void ); static void yyensure_buffer_stack (void ); static void yy_load_buffer_state (void ); static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); #define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); void *yyalloc (yy_size_t ); void *yyrealloc (void *,yy_size_t ); void yyfree (void * ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ yyensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ yy_create_buffer(yyin,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ yyensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ yy_create_buffer(yyin,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ #define yywrap(n) 1 #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; typedef int yy_state_type; extern int yylineno; int yylineno = 1; extern char *yytext; #define yytext_ptr yytext static yy_state_type yy_get_previous_state (void ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); static int yy_get_next_buffer (void ); static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ yyleng = (size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 19 #define YY_END_OF_BUFFER 20 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info { flex_int32_t yy_verify; flex_int32_t yy_nxt; }; static yyconst flex_int16_t yy_accept[28] = { 0, 0, 0, 20, 18, 1, 2, 3, 17, 6, 11, 4, 14, 0, 16, 6, 11, 7, 10, 9, 5, 14, 15, 8, 13, 13, 12, 0 } ; static yyconst flex_int32_t yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 5, 1, 1, 1, 1, 1, 1, 1, 1, 6, 7, 6, 7, 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 10, 1, 9, 9, 9, 9, 11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; static yyconst flex_int32_t yy_meta[12] = { 0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1 } ; static yyconst flex_int16_t yy_base[29] = { 0, 0, 0, 36, 37, 37, 37, 37, 30, 6, 26, 8, 9, 28, 37, 26, 23, 22, 21, 20, 0, 0, 37, 13, 19, 18, 15, 37, 21 } ; static yyconst flex_int16_t yy_def[29] = { 0, 27, 1, 27, 27, 27, 27, 27, 28, 27, 27, 27, 27, 28, 27, 27, 27, 11, 27, 27, 11, 12, 27, 27, 27, 27, 27, 0, 27 } ; static yyconst flex_int16_t yy_nxt[49] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 4, 12, 15, 16, 17, 19, 20, 21, 21, 21, 21, 23, 13, 26, 24, 25, 26, 26, 23, 18, 17, 18, 15, 22, 18, 14, 27, 3, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27 } ; static yyconst flex_int16_t yy_chk[49] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 11, 11, 12, 12, 12, 12, 23, 28, 26, 23, 24, 25, 24, 19, 18, 17, 16, 15, 13, 10, 8, 3, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27 } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; extern int yy_flex_debug; int yy_flex_debug = 0; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ #define REJECT reject_used_but_not_detected #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; #line 1 "exolex.lex" #line 3 "exolex.lex" /**************************************************************/ /* exolex.lex */ /* I.U.T. de Nice - Departement Informatique - C. Hulin */ /* */ /**************************************************************/ #include <stdio.h> extern int nblignes; int nberr=0; #line 14 "exolex.lex" /***************/ /* DEFINITIONS */ /***************/ #line 480 "lex.yy.c" #define INITIAL 0 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ #include <unistd.h> #endif #ifndef YY_EXTRA_TYPE #define YY_EXTRA_TYPE void * #endif static int yy_init_globals (void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ int yylex_destroy (void ); int yyget_debug (void ); void yyset_debug (int debug_flag ); YY_EXTRA_TYPE yyget_extra (void ); void yyset_extra (YY_EXTRA_TYPE user_defined ); FILE *yyget_in (void ); void yyset_in (FILE * in_str ); FILE *yyget_out (void ); void yyset_out (FILE * out_str ); yy_size_t yyget_leng (void ); char *yyget_text (void ); int yyget_lineno (void ); void yyset_lineno (int line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. */ #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus extern "C" int yywrap (void ); #else extern int yywrap (void ); #endif #endif static void yyunput (int c,char *buf_ptr ); #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void ); #else static int input (void ); #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE #define YY_READ_BUF_SIZE 8192 #endif /* Copy whatever the last rule matched to the standard output. */ #ifndef ECHO /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ #define ECHO fwrite( yytext, yyleng, 1, yyout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT #define YY_INPUT(buf,result,max_size) \ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ if ( c == '\n' ) \ buf[n++] = (char) c; \ if ( c == EOF && ferror( yyin ) ) \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ result = n; \ } \ else \ { \ errno=0; \ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ { \ if( errno != EINTR) \ { \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ break; \ } \ errno=0; \ clearerr(yyin); \ } \ }\ \ #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause * some compilers to complain about unreachable statements. */ #ifndef yyterminate #define yyterminate() return YY_NULL #endif /* Number of entries by which start-condition stack grows. */ #ifndef YY_START_STACK_INCR #define YY_START_STACK_INCR 25 #endif /* Report a fatal error. */ #ifndef YY_FATAL_ERROR #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif /* end tables serialization structures and prototypes */ /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL #define YY_DECL_IS_OURS 1 extern int yylex (void); #define YY_DECL int yylex (void) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng * have been set up. */ #ifndef YY_USER_ACTION #define YY_USER_ACTION #endif /* Code executed at the end of each rule. */ #ifndef YY_BREAK #define YY_BREAK break; #endif #define YY_RULE_SETUP \ YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; #line 34 "exolex.lex" /* Trace sur la sortie standard. */ #define LEX_DEBUG #ifdef LEX_DEBUG #define LIST0 printf ("(LEX) %s\n", yytext) #define LIST1(c) printf ("(LEX) %s\n", c) #define LIST2(c,d) printf ("(LEX) %s %s\n", c, d) #define LIST3(x,y) printf ("(LEX) %s %c\n", x, y) #define LISTERR(x,y) printf("ERREUR ligne %d : %s\n", x, y) #else #define LIST0 #define LIST1 #define LIST2 #define LIST3 #define LISTERR #endif /***************/ /* REGLES */ /***************/ #line 686 "lex.yy.c" if ( !(yy_init) ) { (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif if ( ! (yy_start) ) (yy_start) = 1; /* first start state */ if ( ! yyin ) yyin = stdin; if ( ! yyout ) yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin,YY_BUF_SIZE ); } yy_load_buffer_state( ); } while ( 1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); /* Support of yytext. */ *yy_cp = (yy_hold_char); /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; yy_current_state = (yy_start); yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 28 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } while ( yy_base[yy_current_state] != 37 ); yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); yy_act = yy_accept[yy_current_state]; } YY_DO_BEFORE_ACTION; do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ *yy_cp = (yy_hold_char); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); goto yy_find_action; case YY_STATE_EOF(INITIAL): #line 57 "exolex.lex" { LIST1("fin de fichier"); return 1;} YY_BREAK case 1: YY_RULE_SETUP #line 59 "exolex.lex" /* ignorer separateur */ YY_BREAK case 2: /* rule 2 can match eol */ YY_RULE_SETUP #line 61 "exolex.lex" { nblignes++; return 0;} YY_BREAK case 3: /* rule 3 can match eol */ YY_RULE_SETUP #line 63 "exolex.lex" /* ignorer separateur */ YY_BREAK case 4: YY_RULE_SETUP #line 65 "exolex.lex" { LIST2("CHIFFRE :", yytext); return 0;} YY_BREAK case 5: YY_RULE_SETUP #line 67 "exolex.lex" { LIST2("NOMBRE :", yytext); return 0;} YY_BREAK case 6: YY_RULE_SETUP #line 69 "exolex.lex" { LISTERR(nblignes, "nombre manquant"); nberr++; return -1;} YY_BREAK case 7: YY_RULE_SETUP #line 71 "exolex.lex" { LIST2("ENTIER RELATIF :", yytext); return 0;} YY_BREAK case 8: YY_RULE_SETUP #line 73 "exolex.lex" { LIST2("NOMBRE DECIMAL :", yytext); return 0;} YY_BREAK case 9: YY_RULE_SETUP #line 75 "exolex.lex" { LISTERR(nblignes, "partie decimale manquante"); nberr++; return -1;} YY_BREAK case 10: YY_RULE_SETUP #line 77 "exolex.lex" { LISTERR(nblignes, "partie entiere manquante"); nberr++; return -1;} YY_BREAK case 11: YY_RULE_SETUP #line 79 "exolex.lex" { LISTERR(nblignes, "ni partie entiere ni partie decimale"); nberr++; return -1;} YY_BREAK case 12: YY_RULE_SETUP #line 81 "exolex.lex" { LIST2("REEL :", yytext); return 0;} YY_BREAK case 13: YY_RULE_SETUP #line 83 "exolex.lex" { LISTERR(nblignes, "exposant manquant"); nberr++; return -1;} YY_BREAK case 14: YY_RULE_SETUP #line 85 "exolex.lex" { LIST2("IDENTIFICATEUR :", yytext); return 0;} YY_BREAK case 15: YY_RULE_SETUP #line 87 "exolex.lex" { LIST2("CHAINE :", yytext); return 0;} YY_BREAK case 16: YY_RULE_SETUP #line 89 "exolex.lex" { LIST1("CHAINE : vide"); return 0;} YY_BREAK case 17: YY_RULE_SETUP #line 91 "exolex.lex" { LISTERR(nblignes, "fin de chaine attendu"); nberr++; return -1;} YY_BREAK case 18: YY_RULE_SETUP #line 93 "exolex.lex" { LIST3("caractere ignore :", yytext[0]); return 0;} YY_BREAK case 19: YY_RULE_SETUP #line 94 "exolex.lex" ECHO; YY_BREAK #line 870 "lex.yy.c" case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = (yy_hold_char); YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) { /* We're scanning a new file or input source. It's * possible that this happened because the user * just pointed yyin at a new source and called * yylex(). If so, then we have to assure * consistency between YY_CURRENT_BUFFER and our * globals. Here is the right place to do so, because * this is the first action (other than possibly a * back-up) that will match for the new input source. */ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } /* Note that here we test for yy_c_buf_p "<=" to the position * of the first EOB in the buffer, since yy_c_buf_p will * already have been incremented past the NUL character * (since all states make transitions on EOB to the * end-of-buffer state). Contrast this with the test * in input(). */ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) { /* This was really a NUL. */ yy_state_type yy_next_state; (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have * yy_get_previous_state() go ahead and do it * for us because it doesn't know how to deal * with the possibility of jamming (and we don't * want to build jamming into it because then it * will run more slowly). */ yy_next_state = yy_try_NUL_trans( yy_current_state ); yy_bp = (yytext_ptr) + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ yy_cp = ++(yy_c_buf_p); yy_current_state = yy_next_state; goto yy_match; } else { yy_cp = (yy_c_buf_p); goto yy_find_action; } } else switch ( yy_get_next_buffer( ) ) { case EOB_ACT_END_OF_FILE: { (yy_did_buffer_switch_on_eof) = 0; if ( yywrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up * yytext, we can now set up * yy_c_buf_p so that if some total * hoser (like flex itself) wants to * call the scanner after we return the * YY_NULL, it'll still work - another * YY_NULL will get returned. */ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; } else { if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: (yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; } break; } default: YY_FATAL_ERROR( "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ } /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer * * Returns a code representing an action: * EOB_ACT_LAST_MATCH - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ static int yy_get_next_buffer (void) { register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; register char *source = (yytext_ptr); register int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; } else { /* We matched some text prior to the EOB, first * process it. */ return EOB_ACT_LAST_MATCH; } } /* Try to read more data. */ /* First move last chars to start of buffer. */ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else { yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = YY_CURRENT_BUFFER; int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; else b->yy_buf_size *= 2; b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); } else /* Can't grow it, we don't own it. */ b->yy_ch_buf = 0; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; } if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), (yy_n_chars), num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } if ( (yy_n_chars) == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; yyrestart(yyin ); } else { ret_val = EOB_ACT_LAST_MATCH; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; } } else ret_val = EOB_ACT_CONTINUE_SCAN; if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } (yy_n_chars) += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ static yy_state_type yy_get_previous_state (void) { register yy_state_type yy_current_state; register char *yy_cp; yy_current_state = (yy_start); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 28 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character * * synopsis * next_state = yy_try_NUL_trans( current_state ); */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { register int yy_is_jam; register char *yy_cp = (yy_c_buf_p); register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 28 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 27); return yy_is_jam ? 0 : yy_current_state; } static void yyunput (int c, register char * yy_bp ) { register char *yy_cp; yy_cp = (yy_c_buf_p); /* undo effects of setting up yytext */ *yy_cp = (yy_hold_char); if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ register yy_size_t number_to_move = (yy_n_chars) + 2; register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; register char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) *--dest = *--source; yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); } *--yy_cp = (char) c; (yytext_ptr) = yy_bp; (yy_hold_char) = *yy_cp; (yy_c_buf_p) = yy_cp; } #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) #else static int input (void) #endif { int c; *(yy_c_buf_p) = (yy_hold_char); if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ *(yy_c_buf_p) = '\0'; else { /* need more input */ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() * sees that we've accumulated a * token and flags that we need to * try matching the token before * proceeding. But for input(), * there's no matching to consider. * So convert the EOB_ACT_LAST_MATCH * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ yyrestart(yyin ); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { if ( yywrap( ) ) return 0; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else return input(); #endif } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + offset; break; } } } c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ *(yy_c_buf_p) = '\0'; /* preserve yytext */ (yy_hold_char) = *++(yy_c_buf_p); return c; } #endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * * @note This function does not reset the start condition to @c INITIAL . */ void yyrestart (FILE * input_file ) { if ( ! YY_CURRENT_BUFFER ){ yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin,YY_BUF_SIZE ); } yy_init_buffer(YY_CURRENT_BUFFER,input_file ); yy_load_buffer_state( ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * */ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) { /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ yyensure_buffer_stack (); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } YY_CURRENT_BUFFER_LVALUE = new_buffer; yy_load_buffer_state( ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ (yy_did_buffer_switch_on_eof) = 1; } static void yy_load_buffer_state (void) { (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; (yy_hold_char) = *(yy_c_buf_p); } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. * * @return the allocated buffer state. */ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; yy_init_buffer(b,file ); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() * */ void yy_delete_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) yyfree((void *) b->yy_ch_buf ); yyfree((void *) b ); } #ifndef __cplusplus extern int isatty (int ); #endif /* __cplusplus */ /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) { int oerrno = errno; yy_flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * */ void yy_flush_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; b->yy_buf_pos = &b->yy_ch_buf[0]; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) yy_load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. * */ void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) { if (new_buffer == NULL) return; yyensure_buffer_stack(); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) (yy_buffer_stack_top)++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * */ void yypop_buffer_state (void) { if (!YY_CURRENT_BUFFER) return; yy_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ static void yyensure_buffer_stack (void) { yy_size_t num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; yy_switch_to_buffer(b ); return b; } /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) { return yy_scan_bytes(yystr,strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n, i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) yyalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = yy_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif static void yy_fatal_error (yyconst char* msg ) { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless #define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ yytext[yyleng] = (yy_hold_char); \ (yy_c_buf_p) = yytext + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ *(yy_c_buf_p) = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. * */ int yyget_lineno (void) { return yylineno; } /** Get the input stream. * */ FILE *yyget_in (void) { return yyin; } /** Get the output stream. * */ FILE *yyget_out (void) { return yyout; } /** Get the length of the current token. * */ yy_size_t yyget_leng (void) { return yyleng; } /** Get the current token. * */ char *yyget_text (void) { return yytext; } /** Set the current line number. * @param line_number * */ void yyset_lineno (int line_number ) { yylineno = line_number; } /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * * @see yy_switch_to_buffer */ void yyset_in (FILE * in_str ) { yyin = in_str ; } void yyset_out (FILE * out_str ) { yyout = out_str ; } int yyget_debug (void) { return yy_flex_debug; } void yyset_debug (int bdebug ) { yy_flex_debug = bdebug ; } static int yy_init_globals (void) { /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ (yy_buffer_stack) = 0; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; (yy_c_buf_p) = (char *) 0; (yy_init) = 0; (yy_start) = 0; /* Defined in main.c */ #ifdef YY_STDINIT yyin = stdin; yyout = stdout; #else yyin = (FILE *) 0; yyout = (FILE *) 0; #endif /* For future reference: Set errno on error, since we are called by * yylex_init() */ return 0; } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ int yylex_destroy (void) { /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ yy_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; yypop_buffer_state(); } /* Destroy the stack itself. */ yyfree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ yy_init_globals( ); return 0; } /* * Internal utility routines. */ #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s ) { register int n; for ( n = 0; s[n]; ++n ) ; return n; } #endif void *yyalloc (yy_size_t size ) { return (void *) malloc( size ); } void *yyrealloc (void * ptr, yy_size_t size ) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); } void yyfree (void * ptr ) { free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 94 "exolex.lex"
the_stack_data/479344.c
#include <sys/sysinfo.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <sys/vfs.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int GetTickCount(void) { struct sysinfo si; sysinfo(&si); return (int)si.uptime; } static unsigned long GetFreeDiskBytes(const char * path) { struct statfs buf; if(statfs(path, &buf) != 0) { perror("statfs"); return 0; } return (unsigned long)buf.f_bfree * 4 * 1024; } unsigned long GetFreeVarSize(void) { return GetFreeDiskBytes("/var"); } int GetFreeMemSize(void) { int fd; fd = open("/proc/meminfo", O_RDONLY); if(fd < 0) { perror("open"); return 0; } char buffer[1024]; memset(buffer, 0, sizeof(buffer)); read(fd, buffer, 1023); close(fd); char * p = strstr(buffer, "MemFree:"); if(p == NULL) { printf("no MemFree\n"); return 0; } p += strlen("MemFree:"); int size = atoi(p); return size * 1024; } int IsFileExists(const char * filename) { if (filename == NULL) return 0; if (access(filename, F_OK) == 0) return 1; return 0; } long GetFileSizeBytes(const char * filename) { struct stat statbuff; if (!filename) return 0; if (stat(filename, &statbuff) == 0) return statbuff.st_size; return 0; }
the_stack_data/178891.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ extern int foo (void); int a; static inline int __attribute__((always_inline)) bar (void) { a = 2; return 0; } int foo (void) { return bar (); }
the_stack_data/1068161.c
#include <float.h> #include <math.h> #include <stdio.h> float smach(char *cmach) { /* -- SuperLU auxiliary routine (version 5.0) -- This uses C99 standard constants, and is thread safe. Must be compiled with "-std=c99" flag. Purpose ======= SMACH returns single precision machine parameters. Arguments ========= CMACH (input) CHARACTER*1 Specifies the value to be returned by SMACH: = 'E' or 'e', SMACH := eps = 'S' or 's , SMACH := sfmin = 'B' or 'b', SMACH := base = 'P' or 'p', SMACH := eps*base = 'N' or 'n', SMACH := t = 'R' or 'r', SMACH := rnd = 'M' or 'm', SMACH := emin = 'U' or 'u', SMACH := rmin = 'L' or 'l', SMACH := emax = 'O' or 'o', SMACH := rmax where eps = relative machine precision sfmin = safe minimum, such that 1/sfmin does not overflow base = base of the machine prec = eps*base t = number of (base) digits in the mantissa rnd = 1.0 when rounding occurs in addition, 0.0 otherwise emin = minimum exponent before (gradual) underflow rmin = underflow threshold - base**(emin-1) emax = largest exponent before overflow rmax = overflow threshold - (base**emax)*(1-eps) ===================================================================== */ float sfmin, small, rmach; extern int lsame_(char *, char *); if (lsame_(cmach, "E")) { rmach = FLT_EPSILON * 0.5; } else if (lsame_(cmach, "S")) { sfmin = FLT_MIN; small = 1. / FLT_MAX; if (small >= sfmin) { /* Use SMALL plus a bit, to avoid the possibility of rounding causing overflow when computing 1/sfmin. */ sfmin = small * (FLT_EPSILON*0.5 + 1.); } rmach = sfmin; } else if (lsame_(cmach, "B")) { rmach = FLT_RADIX; } else if (lsame_(cmach, "P")) { rmach = FLT_EPSILON * 0.5 * FLT_RADIX; } else if (lsame_(cmach, "N")) { rmach = FLT_MANT_DIG; } else if (lsame_(cmach, "R")) { rmach = FLT_ROUNDS; } else if (lsame_(cmach, "M")) { rmach = FLT_MIN_EXP; } else if (lsame_(cmach, "U")) { rmach = FLT_MIN; } else if (lsame_(cmach, "L")) { rmach = FLT_MAX_EXP; } else if (lsame_(cmach, "O")) { rmach = FLT_MAX; } return rmach; } /* end smach */
the_stack_data/125141820.c
#include <stddef.h> #include <stdint.h> #include <stdlib.h> void neuralops_omp_image_crop( size_t in_width, size_t in_height, size_t chan, size_t crop_w, size_t crop_h, ptrdiff_t offset_x, ptrdiff_t offset_y, const float *in_pixels, float *out_pixels) { size_t p_limit = crop_w * crop_h * chan; #pragma omp parallel for for (size_t p = 0; p < p_limit; p++) { size_t u = p % crop_w; size_t v = (p / crop_w) % crop_h; size_t a = p / (crop_w * crop_h); ptrdiff_t x = offset_x + u; ptrdiff_t y = offset_y + v; if (x < 0 || x >= in_width || y < 0 || y >= in_height) { out_pixels[p] = 0.0f; } else { out_pixels[p] = in_pixels[x + in_width * (y + in_height * a)]; } } } void neuralops_omp_image_flip( size_t width, size_t height, size_t chan, const float *in_pixels, float *out_pixels) { size_t p_limit = width * height * chan; #pragma omp parallel for for (size_t p = 0; p < p_limit; p++) { size_t x = p % width; size_t y = (p / width) % height; size_t a = p / (width * height); out_pixels[p] = in_pixels[(width - x - 1) + width * (y + height * a)]; } }
the_stack_data/95450603.c
#include <stdio.h> int flip(int a[255][255], int b[255][255], int m, int n); int main(){ int m,n,i,j; int a[255][255]; int b[255][255]; printf("Input m,n: "); scanf("%d %d",&m,&n); for (i=0; i<m; i++) for (j=0; j<n; j++){ scanf("%d",&a[i][j]); } flip(a,b,m,n); for (i=0; i<n; i++){ for (j=0; j<m; j++){ printf("%d ",b[i][j]); } printf("\n"); } return 0; } int flip(int a[255][255], int b[255][255], int m, int n){ int i,j; for (i=0; i<m; i++) for (j=0; j<n; j++) b[j][i] = a[i][j]; return 0; }
the_stack_data/32951070.c
/* * Write the function any(s1, s2), which returns the first location in the * string s1 where any character from the string s2 occurs, or -1 if s1 * contains no characters from s2. (The standard library function strpbrk * does the same job but return a pointer to the location.) */ int any(char s1[], char s2[]) { int i, j; for (i = 0; s1[i] != '\0'; i++) { for (j = 0; s2[j] != '\0'; j++) { if (s2[j] == s1[i]) { return i; } } } return -1; }
the_stack_data/247019105.c
/* Author: Beesham Sarendranauth, 104854956 Date: 2017/07/03 Description: performs non-recursive operations such as factorials and fibonacci sequence. The operations are selected from a menu presented to the user. */ #include <stdio.h> #include <stdlib.h> //Function prototypes int prompt(); unsigned long long int summation(unsigned int); unsigned long long int factorial(unsigned int); unsigned long long int fibonacci(unsigned int); int gcd(unsigned int, unsigned int); unsigned long long int power(unsigned int, unsigned int); int main(void){ int selection; int input; //variable that holds user input int input2; //variable that holds user input while(selection != EOF){ //displays a menu puts(""); puts("*************"); puts("* Menu *"); puts("*************"); puts("1. Summation"); puts("2. Factorial"); puts("3. Fibonacci"); puts("4. GCD"); puts("5. Power"); puts(""); puts("Please select the number index of your operation e.g 1 \nEnter -1 to quit (ERROR prints upon exit)"); printf("%s","Input: "); scanf("%d", &selection); //switch statement to select appropriate operation switch(selection){ case 1:{ input = prompt(); if(input >= 1){ printf("%s %d %s %llu", "Summation of ", input, " is: ", summation(input)); getchar(); //waits for user to hit Enter to continue } else{ puts("Invalid input!"); getchar(); //waits for user to hit Enter to continue } } break; case 2:{ input = prompt(); if(input >= 0){ printf("%s %d %s %llu", "Factorial of ", input, " is: ", factorial(input)); getchar(); //waits for user to hit Enter to continue }else{ puts("Invalid input!"); getchar(); //waits for user to hit Enter to continue } } break; case 3:{ input = prompt(); if(input >= 0){ printf("%s %d %s %llu", "Fibonacci of ", input, " is: ", fibonacci(input)); getchar(); //waits for user to hit Enter to continue } else{ puts("Invalid input!"); getchar(); //waits for user to hit Enter to continue } } break; case 4:{ input = prompt(); input2 = prompt(); if(input >= 0 && input2 >= 0){ printf("%s%d %d %s%d", "GCD of ", input, input2, "is: ", gcd(input, input2)); getchar(); //waits for user to hit Enter to continue } else{ puts("Invalid input!"); getchar(); //waits for user to hit Enter to continue } } break; case 5:{ input = prompt(); input2 = prompt(); if(input > 0 && input2 >= 0){ printf("%s%d %d %s%llu", "Power of ", input, input2, "is: ", power(input, input2)); getchar(); //waits for user to hit Enter to continue } else{ puts("Invalid input!"); getchar(); //waits for user to hit Enter to continue } } break; default: puts("ERROR: selection must be from the menu shown"); } getchar(); //waits for user to hit Enter to continue } } /* prompt: displays a message to the user asking for input Input: Output: the users input */ int prompt(){ int input; printf("%s", "Please enter a positive integer: "); scanf("%d", &input); return input; } /* summation: adds each number sequence of a given positive integer up to itself e.g 4: 1 + 2 + 3 + 4 = 10 and prints the result Input: a positive integer (n) Output: results */ unsigned long long int summation(unsigned int n){ int results = 0; for(unsigned int i = 1; i <= n; ++i){ results += i; } return results; } /* factorial: multiplies each number sequence of a given positive integer down to 1 e.g 4: 4 * 3 * 2 * 1 = 24 Input: a positive integer (n) Output: results */ unsigned long long int factorial(unsigned int n){ unsigned long long int results = 1; if(n == 0) return 1; for(unsigned int i = n; i > 1; i--){ results *= i; } return results; } /* fibonacci: generates the fibonacci sequence for a positive integer e.g 4: fibonacci(10) = 55 starting sequence number is chosen to be 1. Input: a positive integer (n) where n is the number of sequences Output: results */ unsigned long long int fibonacci(unsigned int n){ unsigned long long int results = 1; //we initialize results to 1 because our seq. starts at 1 int prev = 1, pprev = 1; //var prev is the previous num in the sequence and is seeded with 1 //var pprev is the 2nd previous num in the sequence and is seeded with 1 if(n == 0 || n == 1) return n; //tests base cases as the fib. seq. of 0 is 0 and 1 is 1 //Iteratively calculates the fib. seq. of the input number for (int i = 1; i <= n; i++){ //we already know the first 2 position results of the seq. is 1 and 1, so we just need to calc. from the 3rd position if(i >= 3){ results = (prev) + (pprev); pprev = prev; prev = results; } } return results; } /* gcd: calculates the greatest common divisor of 2 given positive integer Input: 2 positive integers: x, y Output: result (the gcd of the 2 integers) */ int gcd(unsigned int x, unsigned int y){ int results = 1; //results is init. to 1 because all numbers have 1 as a divisor except 0 int max; //the max num of the 2 integers if(y == 0) return x; //base case max = x > y ? x : y; //calculates the max of the 2 integers //determines the GCD of the 2 integers by looping through the count of the max for(unsigned int i = 1; i <= max; i++){ //if the x or y MOD i == 0, then the GCD is the count. ie. i if((x % i == 0) && (y % i == 0)){ results = i; } } return results; } /* power: calcualtes the power of a given integer but a given integer Input: 2 integers; a,b where a is powered by b Output: results (the power of a by b) */ unsigned long long int power(unsigned int a, unsigned int b){ unsigned long long int results = 1; //results init. to 1 because 1^n is still 1 //determines the results of a^b by iteration for(unsigned int i = 0; i < b; i++){ results *= a; } return results; }
the_stack_data/34511449.c
// A wrapper for the Fortran geolocation code int geolocate_wrapper(double *pos, double *vel, double range, double squint, int side, double a, double e2, double *llh, double *lookAngle, double *incidenceAngle) { geolocate_(pos, vel, &range, &squint, &side, &a, &e2, llh, lookAngle, incidenceAngle); return 1; }
the_stack_data/30032.c
#include<stdio.h> #include<math.h> int main(void) { int n1, n2, qd; printf("Primeiro valor: "); scanf("%i", &n1); printf("Segundo valor: "); scanf("%i", &n2); qd = pow(n1, 2) - pow(n2, 2); printf("O quadrado da diferenca entre %i e %i e %i.", n1, n2, qd); return 0; }
the_stack_data/17774.c
#include <stdio.h> #define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t)) void printArray(int arr[], int arrLength) { int i; printf("[ "); for (i = 0; i < arrLength; ++i) { ((i != arrLength - 1) && printf("%d, ", arr[i])) || printf("%d", arr[i]); } printf(" ]"); } // To heapify a subtree rooted with node i which is // an index in arr[]. arrLength is size of heap void MaxHeapify(int arr[], int arrLength, int i) { int left = 2 * i + 1; int right = 2 * i + 2; int largest = i; int temp; if(left < arrLength && arr[left] > arr[i]) { largest = left; } if(right < arrLength && arr[right] > arr[largest]) { largest = right; } if(largest != i) { SWAP(arr[i], arr[largest], temp); MaxHeapify(arr, arrLength, largest); } return; } void BuildMaxHeap(int arr[], int arrLength) { int i; for(i = arrLength / 2 - 1; i >= 0; i--) { MaxHeapify(arr, arrLength, i); } return; } void HeapSort(int arr[], int arrLength) { int i, temp; // Build heap (rearrange array) BuildMaxHeap(arr, arrLength); for(i = arrLength - 1; i >= 0; i--) { SWAP(arr[i], arr[0], temp); MaxHeapify(arr, i, 0); } return; } int main(int argc, char const *argv[]) { int arr[] = {20, 12, 5, 14, 9, 31, 8, 2, 10, 0, 3}; int arrLength = sizeof(arr) / sizeof(int); HeapSort(arr, arrLength); printArray(arr, arrLength); return 0; }
the_stack_data/496614.c
/* * Expression cpp branch. */ int main(void) { if ( #if 1 0 #elif 2 1 #else 2 #endif ) { } return 0; }
the_stack_data/138583.c
#include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); if(a > b) { printf("%d\n", a); } else { printf("%d\n", b); } return 0; }
the_stack_data/190768093.c
/* Nome Professor: Beltrano Aluno: Fulano Matrícula: 651561561 */ #include <stdio.h> int main(int argc, char const *argv[]) { int idade; int matricula; float preco; // preço de um produto genérico int res1; float res2; // aosdoaiksdo idade = 6003; matricula = 0; preco = 2.5; printf("%d\n", idade); return 0; }
the_stack_data/126747.c
int fib(int n) { int i, prevPrev, prev, current; // edge cases: assert(n >= 0); // index must not be negative if (n == 0 || n == 1) { return n; } // we'll be building the fibonacci series from the bottom up // so we'll need to track the previous 2 numbers at each step prevPrev = 0; // 0th fibonacci prev = 1; // 1st fibonacci current = 0; // Declare and initialize current for (i = 1; i < n; i++) { // Iteration 1: current = 2nd fibonacci // Iteration 2: current = 3rd fibonacci // Iteration 3: current = 4th fibonacci // To get nth fibonacci ... do n-1 iterations. current = prev + prevPrev; prevPrev = prev; prev = current; } return current; }
the_stack_data/148578390.c
#include<stdio.h> #include <stdlib.h> #include <string.h> typedef struct stack { char data[100]; struct stack *next; } Stack; int isEmpty(Stack *stack) { return stack != NULL; } void push(Stack **stack, char *data) { Stack *temp; temp = (Stack *) malloc(sizeof(Stack)); strcpy(temp->data, data); temp->next = *stack; *stack = temp; } char *pop(Stack **stack) { Stack *temp; if (isEmpty(*stack)) { temp = *stack; *stack = temp->next; return temp->data; } return ""; } int isOperator(char c) { switch (c) { case '*': case '/': case '+': case '-': case '^': return 1; default: return 0; } } char *convert(char expression[]) { char *a, *b; char temp[100]; Stack *stack = (Stack *) malloc(sizeof(Stack)); stack->next = NULL; stack->data[0] = '\0'; for (int i = (int)strlen(expression) - 1; i >= 0; i--) { if (isOperator(expression[i])) { a = pop(&stack); b = pop(&stack); temp[0] = '('; temp[1] = '\0'; if (a[0]) { strncat(temp, a, strlen(a)); } strncat(temp, &expression[i], 1); if (b[0]) { strncat(temp, b, strlen(b)); } strncat(temp, ")", 1); strncat(temp, "\0", 1); push(&stack, temp); } else { temp[0] = expression[i]; temp[1] = '\0'; push(&stack, temp); } } return stack->data; } int main() { char exp[100]; printf("Enter Prefix expression: "); scanf("%s", exp); printf("Infix: %s", convert(exp)); fflush(stdin); getchar(); }
the_stack_data/101001.c
/* |4.2| * 1. Numa faculdade, os alunos com média maior ou igual a 7,0 são aprovados, * aqueles com média inferior a 3,0 são reprovados e os demais podem fazer * recuperação. Dadas as duas notas de um aluno, mostre a situação dele. */ #include <stdio.h> int main(void) { float media, n1, n2; puts("Entre com as duas notas do aluno separadas por um espaço vazio:"); scanf("%f %f", &n1, &n2); media = (n1+n2)/2; if (media >= 7.0) { puts("Aprovado."); } else if (media <= 3.0) { puts("Reprovado."); } else { puts("Passível de recuperação."); } return 0; }
the_stack_data/107951945.c
// Find maximum and minimum value in a binary search tree #include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node *left; struct Node *right; }; // Time complexity // - Worst case (in case of skewed tree) - O(n) , Average case (for balanced tree) - O(logn) int FindMaximum(struct Node *root) { if (root->right == NULL) return root->data; return FindMaximum(root->right); } int FindMinimum(struct Node *root) { if (root->left == NULL) return root->data; return FindMinimum(root->left); } struct Node *insertIntoTree(struct Node *, int); void displayInorder(struct Node *); int main() { struct Node *root = NULL; root = insertIntoTree(root, 12); root = insertIntoTree(root, 42); root = insertIntoTree(root, 13); root = insertIntoTree(root, 5); root = insertIntoTree(root, 18); root = insertIntoTree(root, 20); root = insertIntoTree(root, 35); displayInorder(root); int maxi = FindMaximum(root); int mini = FindMinimum(root); printf("\nMaximum: %d", maxi); printf("\nMinimum: %d", mini); return 0; } struct Node *insertIntoTree(struct Node *root, int data) { struct Node *newNode = (struct Node *)malloc(sizeof(struct Node)); newNode->data = data; newNode->left = NULL; newNode->right = NULL; if (root == NULL) return newNode; struct Node *curr = root, *parent = NULL; while (curr) { parent = curr; if (data <= curr->data) { curr = curr->left; if (curr == NULL) parent->left = newNode; } else { curr = curr->right; if (curr == NULL) parent->right = newNode; } } return root; } void displayInorder(struct Node *root) { if (root == NULL) return; displayInorder(root->left); printf("%d ", root->data); displayInorder(root->right); }
the_stack_data/832413.c
#include <stdio.h> int S[309], N, M, C[5]; int V[41][41][41][41]; int max(int x1, int x2, int x3, int x4); int main(void) { int i, x, i1, i2, i3, i4; #ifdef DEBUG freopen("in", "r", stdin); #endif scanf("%d%d", &N, &M); for (i = 1; i <= N; ++i) scanf("%d", S + i); for (i = 0; i < M; ++i) { scanf("%d", &x); ++C[x]; } for (i1 = 0; i1 <= C[1]; ++i1) for (i2 = 0; i2 <= C[2]; ++i2) for (i3 = 0; i3 <= C[3]; ++i3) for (i4 = 0; i4 <= C[4]; ++i4) V[i1][i2][i3][i4] = max( ((i1 - 1 >= 0) ? (V[i1 - 1][i2][i3][i4]) : (0)), (((i2 - 1 >= 0)) ? (V[i1][i2 - 1][i3][i4]) : (0)), ((i3 - 1 >= 0) ? (V[i1][i2][i3 - 1][i4]) : (0)), ((i4 - 1 >= 0) ? (V[i1][i2][i3][i4 - 1]) : (0))) + S[i1 + i2 * 2 + i3 * 3 + i4 * 4 + 1]; printf("%d\n", V[C[1]][C[2]][C[3]][C[4]]); return 0; } int max(int x1, int x2, int x3, int x4) { x1 = (x2 > x1) ? (x2) : (x1); x1 = (x3 > x1) ? (x3) : (x1); x1 = (x4 > x1) ? (x4) : (x1); return x1; }
the_stack_data/234517718.c
/* $OpenBSD: unctrl.c,v 1.3 2005/08/14 17:15:19 espie Exp $ */ /* * Copyright (c) 1981, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * 3. Neither the name of the University 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 THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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. */ char *__unctrl[256] = { "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", "^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_", " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "^?", "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", "0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e", "0x8f", "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", "0x98", "0x99", "0x9a", "0x9b", "0x9c", "0x9d", "0x9e", "0x9f", "0xa0", "0xa1", "0xa2", "0xa3", "0xa4", "0xa5", "0xa6", "0xa7", "0xa8", "0xa9", "0xaa", "0xab", "0xac", "0xad", "0xae", "0xaf", "0xb0", "0xb1", "0xb2", "0xb3", "0xb4", "0xb5", "0xb6", "0xb7", "0xb8", "0xb9", "0xba", "0xbb", "0xbc", "0xbd", "0xbe", "0xbf", "0xc0", "0xc1", "0xc2", "0xc3", "0xc4", "0xc5", "0xc6", "0xc7", "0xc8", "0xc9", "0xca", "0xcb", "0xcc", "0xcd", "0xce", "0xcf", "0xd0", "0xd1", "0xd2", "0xd3", "0xd4", "0xd5", "0xd6", "0xd7", "0xd8", "0xd9", "0xda", "0xdb", "0xdc", "0xdd", "0xde", "0xdf", "0xe0", "0xe1", "0xe2", "0xe3", "0xe4", "0xe5", "0xe6", "0xe7", "0xe8", "0xe9", "0xea", "0xeb", "0xec", "0xed", "0xee", "0xef", "0xf0", "0xf1", "0xf2", "0xf3", "0xf4", "0xf5", "0xf6", "0xf7", "0xf8", "0xf9", "0xfa", "0xfb", "0xfc", "0xfd", "0xfe", "0xff", }; char __unctrllen[256] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, };
the_stack_data/100140747.c
/** ****************************************************************************** * @file stm32wbxx_ll_crc.c * @author MCD Application Team * @brief CRC LL module driver. ****************************************************************************** * @attention * * Copyright (c) 2019 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 "stm32wbxx_ll_crc.h" #include "stm32wbxx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ /** @addtogroup STM32WBxx_LL_Driver * @{ */ #if defined (CRC) /** @addtogroup CRC_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup CRC_LL_Exported_Functions * @{ */ /** @addtogroup CRC_LL_EF_Init * @{ */ /** * @brief De-initialize CRC registers (Registers restored to their default values). * @param CRCx CRC Instance * @retval An ErrorStatus enumeration value: * - SUCCESS: CRC registers are de-initialized * - ERROR: CRC registers are not de-initialized */ ErrorStatus LL_CRC_DeInit(CRC_TypeDef *CRCx) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_CRC_ALL_INSTANCE(CRCx)); if (CRCx == CRC) { /* Force CRC reset */ LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_CRC); /* Release CRC reset */ LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_CRC); } else { status = ERROR; } return (status); } /** * @} */ /** * @} */ /** * @} */ #endif /* defined (CRC) */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */
the_stack_data/1158496.c
#include <stdio.h> int main() { char chr; printf("Enter a character: "); scanf("%c", &chr); // when %c is used, a character is displayed printf("You entered %c.\n", chr); // when %d is used, ASCII value is displayed printf("ASCII value is %d.", chr); return 0; }
the_stack_data/100389.c
// Napisać program obliczający silnię z podanej, // niezbyt dużej, liczby naturalnej. #include<stdio.h> void take_input(int *user_input); void count_factorial_and_print_out(int user_input); int main() { int user_input; take_input(&user_input); count_factorial_and_print_out(user_input); } void take_input(int *user_input) { printf("Podaj niezbyt duza liczbe naturalna: "); scanf("%d", user_input); } void count_factorial_and_print_out(int user_input) { int res = 1; while(user_input > 0) { res = res * user_input; user_input--; } printf("Silnia wynosi: %d\n", res); }
the_stack_data/148579018.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2009-2014 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ main(int argc, char *argv[]) { int i; for (i = 0; i < argc; ++i) { printf("Arg %d is %s\n", i, argv[i]); } }
the_stack_data/92324725.c
#define msg "Hello World\n" int main( int argc, char * argv[] ) { int y; y = factorial(6); printf(msg); printf("6! = %d\n", y); } int factorial(int x) { if ( x == 1 ) return 1; return x * factorial(x-1); }
the_stack_data/62129.c
/* { dg-do run } */ /* { dg-options "-O2 -foptimize-sibling-calls" } */ typedef struct { int data[4]; } arr16_t; int result = 0; void func2(int i, int j, arr16_t arr) { result = (arr.data[0] != 1 || arr.data[1] != 2 || arr.data[2] != 3 || arr.data[3] != 4); } void func1(int i, int j, int k, arr16_t a) { func2(i, j, a); } int main(int argc, const char *argv[]) { arr16_t arr = {{1, 2, 3, 4}}; func1(0, 0, 0, arr); return result; }
the_stack_data/364846.c
/** * @file lv_port_indev.c * */ /*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/ #if 0 /********************* * INCLUDES *********************/ #include "lv_port_indev.h" #include "../../lvgl.h" /********************* * DEFINES *********************/ /********************** * TYPEDEFS **********************/ /********************** * STATIC PROTOTYPES **********************/ static void touchpad_init(void); static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static bool touchpad_is_pressed(void); static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y); static void mouse_init(void); static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static bool mouse_is_pressed(void); static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y); static void keypad_init(void); static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static uint32_t keypad_get_key(void); static void encoder_init(void); static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static void encoder_handler(void); static void button_init(void); static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); static int8_t button_get_pressed_id(void); static bool button_is_pressed(uint8_t id); /********************** * STATIC VARIABLES **********************/ lv_indev_t * indev_touchpad; lv_indev_t * indev_mouse; lv_indev_t * indev_keypad; lv_indev_t * indev_encoder; lv_indev_t * indev_button; static int32_t encoder_diff; static lv_indev_state_t encoder_state; /********************** * MACROS **********************/ /********************** * GLOBAL FUNCTIONS **********************/ void lv_port_indev_init(void) { /** * Here you will find example implementation of input devices supported by LittelvGL: * - Touchpad * - Mouse (with cursor support) * - Keypad (supports GUI usage only with key) * - Encoder (supports GUI usage only with: left, right, push) * - Button (external buttons to press points on the screen) * * The `..._read()` function are only examples. * You should shape them according to your hardware */ static lv_indev_drv_t indev_drv; /*------------------ * Touchpad * -----------------*/ /*Initialize your touchpad if you have*/ touchpad_init(); /*Register a touchpad input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.read_cb = touchpad_read; indev_touchpad = lv_indev_drv_register(&indev_drv); /*------------------ * Mouse * -----------------*/ /*Initialize your touchpad if you have*/ mouse_init(); /*Register a mouse input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.read_cb = mouse_read; indev_mouse = lv_indev_drv_register(&indev_drv); /*Set cursor. For simplicity set a HOME symbol now.*/ lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act()); lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME); lv_indev_set_cursor(indev_mouse, mouse_cursor); /*------------------ * Keypad * -----------------*/ /*Initialize your keypad or keyboard if you have*/ keypad_init(); /*Register a keypad input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_KEYPAD; indev_drv.read_cb = keypad_read; indev_keypad = lv_indev_drv_register(&indev_drv); /*Later you should create group(s) with `lv_group_t * group = lv_group_create()`, *add objects to the group with `lv_group_add_obj(group, obj)` *and assign this input device to group to navigate in it: *`lv_indev_set_group(indev_keypad, group);`*/ /*------------------ * Encoder * -----------------*/ /*Initialize your encoder if you have*/ encoder_init(); /*Register a encoder input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_ENCODER; indev_drv.read_cb = encoder_read; indev_encoder = lv_indev_drv_register(&indev_drv); /*Later you should create group(s) with `lv_group_t * group = lv_group_create()`, *add objects to the group with `lv_group_add_obj(group, obj)` *and assign this input device to group to navigate in it: *`lv_indev_set_group(indev_encoder, group);`*/ /*------------------ * Button * -----------------*/ /*Initialize your button if you have*/ button_init(); /*Register a button input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_BUTTON; indev_drv.read_cb = button_read; indev_button = lv_indev_drv_register(&indev_drv); /*Assign buttons to points on the screen*/ static const lv_point_t btn_points[2] = { {10, 10}, /*Button 0 -> x:10; y:10*/ {40, 100}, /*Button 1 -> x:40; y:100*/ }; lv_indev_set_button_points(indev_button, btn_points); } /********************** * STATIC FUNCTIONS **********************/ /*------------------ * Touchpad * -----------------*/ /*Initialize your touchpad*/ static void touchpad_init(void) { /*Your code comes here*/ } /*Will be called by the library to read the touchpad*/ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static lv_coord_t last_x = 0; static lv_coord_t last_y = 0; /*Save the pressed coordinates and the state*/ if(touchpad_is_pressed()) { touchpad_get_xy(&last_x, &last_y); data->state = LV_INDEV_STATE_PR; } else { data->state = LV_INDEV_STATE_REL; } /*Set the last pressed coordinates*/ data->point.x = last_x; data->point.y = last_y; } /*Return true is the touchpad is pressed*/ static bool touchpad_is_pressed(void) { /*Your code comes here*/ return false; } /*Get the x and y coordinates if the touchpad is pressed*/ static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y) { /*Your code comes here*/ (*x) = 0; (*y) = 0; } /*------------------ * Mouse * -----------------*/ /*Initialize your mouse*/ static void mouse_init(void) { /*Your code comes here*/ } /*Will be called by the library to read the mouse*/ static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { /*Get the current x and y coordinates*/ mouse_get_xy(&data->point.x, &data->point.y); /*Get whether the mouse button is pressed or released*/ if(mouse_is_pressed()) { data->state = LV_INDEV_STATE_PR; } else { data->state = LV_INDEV_STATE_REL; } } /*Return true is the mouse button is pressed*/ static bool mouse_is_pressed(void) { /*Your code comes here*/ return false; } /*Get the x and y coordinates if the mouse is pressed*/ static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y) { /*Your code comes here*/ (*x) = 0; (*y) = 0; } /*------------------ * Keypad * -----------------*/ /*Initialize your keypad*/ static void keypad_init(void) { /*Your code comes here*/ } /*Will be called by the library to read the mouse*/ static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static uint32_t last_key = 0; /*Get the current x and y coordinates*/ mouse_get_xy(&data->point.x, &data->point.y); /*Get whether the a key is pressed and save the pressed key*/ uint32_t act_key = keypad_get_key(); if(act_key != 0) { data->state = LV_INDEV_STATE_PR; /*Translate the keys to LVGL control characters according to your key definitions*/ switch(act_key) { case 1: act_key = LV_KEY_NEXT; break; case 2: act_key = LV_KEY_PREV; break; case 3: act_key = LV_KEY_LEFT; break; case 4: act_key = LV_KEY_RIGHT; break; case 5: act_key = LV_KEY_ENTER; break; } last_key = act_key; } else { data->state = LV_INDEV_STATE_REL; } data->key = last_key; } /*Get the currently being pressed key. 0 if no key is pressed*/ static uint32_t keypad_get_key(void) { /*Your code comes here*/ return 0; } /*------------------ * Encoder * -----------------*/ /*Initialize your keypad*/ static void encoder_init(void) { /*Your code comes here*/ } /*Will be called by the library to read the encoder*/ static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { data->enc_diff = encoder_diff; data->state = encoder_state; } /*Call this function in an interrupt to process encoder events (turn, press)*/ static void encoder_handler(void) { /*Your code comes here*/ encoder_diff += 0; encoder_state = LV_INDEV_STATE_REL; } /*------------------ * Button * -----------------*/ /*Initialize your buttons*/ static void button_init(void) { /*Your code comes here*/ } /*Will be called by the library to read the button*/ static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { static uint8_t last_btn = 0; /*Get the pressed button's ID*/ int8_t btn_act = button_get_pressed_id(); if(btn_act >= 0) { data->state = LV_INDEV_STATE_PR; last_btn = btn_act; } else { data->state = LV_INDEV_STATE_REL; } /*Save the last pressed button's ID*/ data->btn_id = last_btn; } /*Get ID (0, 1, 2 ..) of the pressed button*/ static int8_t button_get_pressed_id(void) { uint8_t i; /*Check to buttons see which is being pressed (assume there are 2 buttons)*/ for(i = 0; i < 2; i++) { /*Return the pressed button's ID*/ if(button_is_pressed(i)) { return i; } } /*No button pressed*/ return -1; } /*Test if `id` button is pressed or not*/ static bool button_is_pressed(uint8_t id) { /*Your code comes here*/ return false; } #else /*Enable this file at the top*/ /*This dummy typedef exists purely to silence -Wpedantic.*/ typedef int keep_pedantic_happy; #endif
the_stack_data/402687.c
/* { dg-do compile } */ /* { dg-require-effective-target lto } */ /* { dg-options "-flto -march=x86-64" } */ extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__, target("sse2"))) _mm_loadu_si128 (int const *__P) { return *__P; } void __attribute__((target("ssse3"))) foo (void *p) { volatile int x = _mm_loadu_si128 (p); }
the_stack_data/107953416.c
// possible deadlock in mnt_want_write // https://syzkaller.appspot.com/bug?id=9253638353fa73b900167c64495455f5327644bd // status:open // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <sched.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <unistd.h> #include <linux/if_addr.h> #include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/in6.h> #include <linux/ip.h> #include <linux/neighbour.h> #include <linux/net.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/tcp.h> #include <linux/veth.h> unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static struct { char* pos; int nesting; struct nlattr* nested[8]; char buf[1024]; } nlmsg; static void netlink_init(int typ, int flags, const void* data, int size) { memset(&nlmsg, 0, sizeof(nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; memcpy(attr + 1, data, size); nlmsg.pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(int typ) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_type = typ; nlmsg.pos += sizeof(*attr); nlmsg.nested[nlmsg.nesting++] = attr; } static void netlink_done(void) { struct nlattr* attr = nlmsg.nested[--nlmsg.nesting]; attr->nla_len = nlmsg.pos - (char*)attr; } static int netlink_send(int sock) { if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_len = nlmsg.pos - nlmsg.buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != hdr->nlmsg_len) exit(1); n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0); if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr)) exit(1); if (hdr->nlmsg_type != NLMSG_ERROR) exit(1); return -((struct nlmsgerr*)(hdr + 1))->error; } static void netlink_add_device_impl(const char* type, const char* name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(IFLA_IFNAME, name, strlen(name)); netlink_nest(IFLA_LINKINFO); netlink_attr(IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(int sock, const char* type, const char* name) { netlink_add_device_impl(type, name); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_veth(int sock, const char* name, const char* peer) { netlink_add_device_impl("veth", name); netlink_nest(IFLA_INFO_DATA); netlink_nest(VETH_INFO_PEER); nlmsg.pos += sizeof(struct ifinfomsg); netlink_attr(IFLA_IFNAME, peer, strlen(peer)); netlink_done(); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_hsr(int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl("hsr", name); netlink_nest(IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_device_change(int sock, const char* name, bool up, const char* master, const void* mac, int macsize) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr)); netlink_attr(IFLA_IFNAME, name, strlen(name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(IFLA_ADDRESS, mac, macsize); int err = netlink_send(sock); (void)err; } static int netlink_add_addr(int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(IFA_LOCAL, addr, addrsize); netlink_attr(IFA_ADDRESS, addr, addrsize); return netlink_send(sock); } static void netlink_add_addr4(int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr)); (void)err; } static void netlink_add_addr6(int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr)); (void)err; } static void netlink_add_neigh(int sock, const char* name, const void* addr, int addrsize, const void* mac, int macsize) { struct ndmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ndm_ifindex = if_nametoindex(name); hdr.ndm_state = NUD_PERMANENT; netlink_init(RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); netlink_attr(NDA_DST, addr, addrsize); netlink_attr(NDA_LLADDR, mac, macsize); int err = netlink_send(sock); (void)err; } static int tunfd = -1; static int tun_frags_enabled; #define SYZ_TUN_MAX_PACKET_SIZE 1000 #define TUN_IFACE "syz_tun" #define LOCAL_MAC 0xaaaaaaaaaaaa #define REMOTE_MAC 0xaaaaaaaaaabb #define LOCAL_IPV4 "172.20.20.170" #define REMOTE_IPV4 "172.20.20.187" #define LOCAL_IPV6 "fe80::aa" #define REMOTE_IPV6 "fe80::bb" #define IFF_NAPI 0x0010 #define IFF_NAPI_FRAGS 0x0020 static void initialize_tun(void) { tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as intended\n"); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) exit(1); } if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0) exit(1); tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0; char sysctl[64]; sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE); write_file(sysctl, "0"); sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE); write_file(sysctl, "0"); int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); netlink_add_addr4(sock, TUN_IFACE, LOCAL_IPV4); netlink_add_addr6(sock, TUN_IFACE, LOCAL_IPV6); uint64_t macaddr = REMOTE_MAC; struct in_addr in_addr; inet_pton(AF_INET, REMOTE_IPV4, &in_addr); netlink_add_neigh(sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr, ETH_ALEN); struct in6_addr in6_addr; inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr); netlink_add_neigh(sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr, ETH_ALEN); macaddr = LOCAL_MAC; netlink_device_change(sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN); close(sock); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02x" #define DEV_MAC 0x00aaaaaaaaaa static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"netdevsim", netdevsim}, {"veth", 0}, }; const char* devmasters[] = {"bridge", "bond", "team"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(sock, slave0, false, master, 0, 0); netlink_device_change(sock, slave1, false, master, 0, 0); } netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0); netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0); netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0); netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(sock, devices[i].name, true, 0, &macaddr, devices[i].macsize); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1); netlink_add_addr6(sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize); } close(sock); } static void setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) { } write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:"); write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC"); } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } setup_binfmt_misc(); } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } initialize_tun(); initialize_netdevices(); loop(); exit(1); } #define SYZ_HAVE_CLOSE_FDS 1 static void close_fds() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } void loop(void) { NONFAILING(memcpy((void*)0x20000140, "./file1\000", 8)); syscall(__NR_mkdir, 0x20000140, 0); NONFAILING(memcpy((void*)0x20000340, "./file1/file0\000", 14)); syscall(__NR_creat, 0x20000340, 0); NONFAILING(memcpy((void*)0x200001c0, "./file0\000", 8)); syscall(__NR_mkdir, 0x200001c0, 0); NONFAILING(memcpy((void*)0x20000480, "./file0\000", 8)); NONFAILING(memcpy((void*)0x200004c0, "overlay\000", 8)); NONFAILING(memcpy((void*)0x20000c40, "upperdir=./file0,lowerdir=./file1,workdir=./file1", 49)); syscall(__NR_mount, 0x400000, 0x20000480, 0x200004c0, 0, 0x20000c40); NONFAILING(memcpy((void*)0x20000540, "./file0\000", 8)); syscall(__NR_chdir, 0x20000540); NONFAILING(memcpy((void*)0x20000040, "./file0\000", 8)); syscall(__NR_open, 0x20000040, 0x927, 0); close_fds(); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; }
the_stack_data/152292.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <time.h> #include <assert.h> /* * Generate random reudcer based on the * the following three params: * variable number, line number, if-else * numbers. The variable passed to the * Outputcollector or Context is selected * randomly. */ /* * Structs */ typedef struct Array { int size; char** elements; // For Opers int* is_binary; } Array; /* * Static Variables */ static Array* Vars = NULL; static Array* Opers = NULL; static Array* Cmps = NULL; static int File_fd; static int* Line_types; // Line_types: // 0 -> normal // 1 -> "if (--) {" // 2 -> "} else {" // 3 -> "}" static int VAR_NUM = 7; static int IF_NUM = 10; static int BASELINE = 200; static int LINE = 0; /* * Functions */ int writeline(char *str) { int size = 0; int length = strlen(str); char *ptr = str; while (size < length) { int n = write(File_fd, ptr, length - size); ptr += n; size += n; } return size; } int get_random(int max) { if (max == 0) return 0; int random = rand(); return random % max; } int open_filefd(char* filename) { int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (fd < 0) { fprintf(stderr, "File fd failed\n"); exit(1); } return fd; } Array* init_Array() { Array* array = malloc(sizeof(Array)); array->size = 0; array->elements = NULL; array->is_binary = NULL; return array; } void push_element(Array* array, char* element) { if (element == NULL) return; array->size++; array->elements = realloc(array->elements, sizeof(char*) * array->size); array->elements[array->size - 1] = strdup(element); } void push_oper(Array* array, char* operation, int is_binary) { if (operation == NULL) return; array->size++; array->elements = realloc(array->elements, sizeof(char*) * array->size); array->elements[array->size - 1] = strdup(operation); array->is_binary = realloc(array->is_binary, sizeof(int*) * array->size); array->is_binary[array->size - 1] = is_binary; } void init_vars() { char c = 'a'; for (int i = 0; i < VAR_NUM; i++) { char* str = malloc(5); str[0] = c; str[1] = i / 100 + '0'; str[2] = (i % 100) / 10 + '0'; str[3] = (i % 10) + '0'; str[4] = '\0'; push_element(Vars, str); free(str); } } void init_opers() { push_oper(Opers, "+", 1); push_oper(Opers, "-", 1); push_oper(Opers, "*", 1); push_oper(Opers, "/", 1); push_oper(Opers, "%", 1); push_oper(Opers, "+=", 0); push_oper(Opers, "-=", 0); push_oper(Opers, "*=", 0); push_oper(Opers, "/=", 0); } void init_cmps() { push_element(Cmps, "=="); push_element(Cmps, "!="); push_element(Cmps, ">="); push_element(Cmps, "<="); push_element(Cmps, ">"); push_element(Cmps, "<"); } void init_line_types() { Line_types = malloc(sizeof(int) * LINE); for (int i = 0; i < LINE; i++) Line_types[i] = 0; if (IF_NUM <= 0) return; int if_else_end[3] = {IF_NUM, 0, 0}; int hierachy_stack[IF_NUM]; int hierachy = 0; int total = IF_NUM * 3; int done = 0; int current_line = 0; int target_line = 0; int avaliable = 0; int avaliable_list[3] = {-1, -1, -1}; int range_max = LINE / IF_NUM / 3; for (int i = 0; i < IF_NUM; i++) hierachy_stack[i] = 0; for (int i = 0; i < total; i++) { int range = (LINE - (total - done) - current_line); range = range > range_max ? (range_max * 2) : range; target_line = get_random(range) + current_line; avaliable = 0; if (hierachy_stack[hierachy] == 0) { if (if_else_end[0] > 0) { avaliable_list[avaliable] = 0; avaliable++; } } else if (hierachy_stack[hierachy] == 1) { for (int j = 0; j < 3; j++) { if (j != 2 && if_else_end[j] > 0) { avaliable_list[avaliable] = j; avaliable++; } } } else { for (int j = 0; j < 3; j++) { if (j != 1 && if_else_end[j] > 0) { avaliable_list[avaliable] = j; avaliable++; } } } int target = get_random(avaliable); if (avaliable_list[target] == 0) { Line_types[target_line] = 1; if_else_end[0]--; if_else_end[1]++; if (hierachy_stack[hierachy] == 0) { hierachy_stack[hierachy] = 1; } else { hierachy_stack[++hierachy] = 1; } } else if (avaliable_list[target] == 1) { Line_types[target_line] = 2; if_else_end[1]--; if_else_end[2]++; hierachy_stack[hierachy] = 2; } else { Line_types[target_line] = 3; if_else_end[2]--; hierachy_stack[hierachy] = 0; if (hierachy != 0) hierachy--; } done++; current_line = target_line + 1; assert(current_line <= LINE); } assert(hierachy == 0); } void destroy_Array(Array* array) { if (array->elements != NULL) { for (int i = 0; i < array->size; i++) { free(array->elements[i]); array->elements[i] = NULL; } free(array->elements); array->elements = NULL; } if (array->is_binary != NULL) { free(array->is_binary); } free(array); } void write_init_vars() { for(int i = 0; i < Vars->size; i++) { writeline("int "); writeline(Vars->elements[i]); writeline(" = 0;\n"); } writeline("\n"); } void write_func_sig() { char name[16]; snprintf(name, 16, "int f_%02d(", Vars->size); writeline(name); for(int i = 0; i < Vars->size; i++) { writeline("int "); writeline(Vars->elements[i]); if (i < Vars->size - 1) { writeline(", "); } } writeline(") {\n"); } void sum_up_vars() { for(int i = 0; i < Vars->size; i++) { writeline("sum += "); writeline(Vars->elements[i]); writeline(";\n"); } writeline("\n"); } char* generate_normal_line() { // 1% have * if (get_random(100) == 1) { int lhs_i = get_random(Vars->size); char** rhs = malloc(sizeof(char*) * 2); int rhs_i = get_random(Vars->size); rhs[0] = strdup(Vars->elements[rhs_i]); asprintf(&rhs[1], "%d", get_random(10) - 5); char *result = NULL; asprintf(&result, "%s = %s * %s;\n", Vars->elements[lhs_i], rhs[0], rhs[1]); free(rhs[0]); free(rhs[1]); free(rhs); return result; } int lhs_i = get_random(Vars->size); int op_i = get_random(Opers->size); if (Opers->is_binary[op_i] == 1) { char** rhs = malloc(sizeof(char*) * 2); for (int i = 0; i < 2; i++) { int rhs_i = get_random(Vars->size + 1); if (rhs_i == Vars->size) asprintf(&rhs[i], "%d", get_random(10) - 5); else rhs[i] = strdup(Vars->elements[rhs_i]); } char *result = NULL; asprintf(&result, "%s = %s %s %s;\n", Vars->elements[lhs_i], rhs[0], Opers->elements[op_i], rhs[1]); free(rhs[0]); free(rhs[1]); free(rhs); return result; } else { int rhs_i = get_random(Vars->size + 1); char *rhs = NULL; if (rhs_i == Vars->size) asprintf(&rhs, "%d", get_random(10) - 5); else rhs = strdup(Vars->elements[rhs_i]); char *result = NULL; asprintf(&result, "%s %s %s;\n", Vars->elements[lhs_i], Opers->elements[op_i], rhs); free(rhs); return result; } } char* generate_condition() { int cmp_i = get_random(Cmps->size); int lhs_i = get_random(Vars->size); int rhs_i = get_random(Vars->size + 1); char *rhs = NULL; if (rhs_i == Vars->size) asprintf(&rhs, "%d", get_random(10) - 5); else rhs = strdup(Vars->elements[rhs_i]); char *result = NULL; asprintf(&result, "%s %s %s", Vars->elements[lhs_i], Cmps->elements[cmp_i], rhs); free(rhs); return result; } void write_body_lines() { for (int i = 0; i < LINE; i++) { if (Line_types[i] == 0) { char *str = generate_normal_line(); writeline(str); free(str); } else if (Line_types[i] == 1) { writeline("if ("); char *str = generate_condition(); writeline(str); writeline(") {\n"); free(str); } else if (Line_types[i] == 2) { writeline("} else {\n"); } else if (Line_types[i] == 3) { writeline("}\n"); } } } int main(int argc, char** argv) { if (argc != 2 && argc != 5) { fprintf(stderr, "./generator filename <Variable Baseline If-else>\n"); exit(1); } if (argc == 5) { VAR_NUM = atoi(argv[2]); BASELINE = atoi(argv[3]); IF_NUM = atoi(argv[4]); } else { VAR_NUM = 7; IF_NUM = 10; BASELINE = 200; } assert(IF_NUM >= 0); assert(VAR_NUM >= 0); assert(BASELINE > 0); LINE = (BASELINE + IF_NUM * 3); srand(time(NULL)); File_fd = open_filefd(argv[1]); Vars = init_Array(); Opers = init_Array(); Cmps = init_Array(); writeline("// Note: only +, - operations\n"); writeline("// Parameters:\n"); char *str = NULL; asprintf(&str, "// Variables: %d\n", VAR_NUM); writeline(str); free(str); str = NULL; asprintf(&str, "// Baselines: %d\n", BASELINE); writeline(str); free(str); str = NULL; asprintf(&str, "// If-Branches: %d\n\n", IF_NUM); writeline(str); free(str); str = NULL; init_vars(); init_opers(); init_cmps(); init_line_types(); push_element(Vars, "cur"); write_func_sig(); write_body_lines(); writeline("return cur;\n}\n"); destroy_Array(Vars); destroy_Array(Opers); destroy_Array(Cmps); free(Line_types); Line_types = NULL; close(File_fd); printf("Successly saved to %s\n", argv[1]); return 0; }
the_stack_data/2624.c
// RUN: touch %t.o // RUN: %clang -target arm64_32-apple-watchos5.2 -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck %s // RUN: %clang -target x86_64-apple-watchos6-simulator -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=520 -### %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=SIMUL %s // CHECK: "-platform_version" "watchos" "5.2.0" "6.0.0" // SIMUL: "-platform_version" "watchos-simulator" "6.0.0" "6.0.0"
the_stack_data/29825371.c
/* $NetBSD: otto.c,v 1.8 2004/11/05 21:30:32 dsl Exp $ */ # ifdef OTTO /* * Copyright (c) 1983-2003, Regents of the University of California. * 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 University of California, San Francisco 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT * OWNER OR CONTRIBUTORS 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. */ /* * otto - a hunt otto-matic player * * This guy is buggy, unfair, stupid, and not extensible. * Future versions of hunt will have a subroutine library for * automatic players to link to. If you write your own "otto" * please let us know what subroutines you would expect in the * subroutine library. * * Id: otto.c,v 1.14 2003/04/16 06:11:54 gregc Exp */ #include <sys/cdefs.h> #ifndef lint __RCSID("$NetBSD: otto.c,v 1.8 2004/11/05 21:30:32 dsl Exp $"); #endif /* not lint */ # include <sys/time.h> # include <curses.h> # include <ctype.h> # include <signal.h> # include <stdlib.h> # include <unistd.h> # include "hunt.h" # undef WALL # undef NORTH # undef SOUTH # undef WEST # undef EAST # undef FRONT # undef LEFT # undef BACK # undef RIGHT # ifdef HPUX # define random rand # endif # ifndef USE_CURSES extern char screen[SCREEN_HEIGHT][SCREEN_WIDTH2]; # define SCREEN(y, x) screen[y][x] # else # define SCREEN(y, x) mvinch(y, x) # endif # ifndef DEBUG # define STATIC static # else # define STATIC # endif # define OPPONENT "{}i!" # define PROPONENT "^v<>" # define WALL "+\\/#*-|" # define PUSHOVER " bg;*#&" # define SHOTS "$@Oo:" /* number of "directions" */ # define NUMDIRECTIONS 4 /* absolute directions (facings) - counterclockwise */ # define NORTH 0 # define WEST 1 # define SOUTH 2 # define EAST 3 # define ALLDIRS 0xf /* relative directions - counterclockwise */ # define FRONT 0 # define LEFT 1 # define BACK 2 # define RIGHT 3 # define ABSCHARS "NWSE" # define RELCHARS "FLBR" # define DIRKEYS "khjl" STATIC char command[BUFSIZ]; STATIC int comlen; # ifdef DEBUG STATIC FILE *debug = NULL; # endif # define DEADEND 0x1 # define ON_LEFT 0x2 # define ON_RIGHT 0x4 # define ON_SIDE (ON_LEFT|ON_RIGHT) # define BEEN 0x8 # define BEEN_SAME 0x10 struct item { char what; int distance; int flags; }; STATIC struct item flbr[NUMDIRECTIONS]; # define fitem flbr[FRONT] # define litem flbr[LEFT] # define bitem flbr[BACK] # define ritem flbr[RIGHT] STATIC int facing; STATIC int row, col; STATIC int num_turns; /* for wandering */ STATIC char been_there[HEIGHT][WIDTH2]; STATIC struct itimerval pause_time = { { 0, 0 }, { 0, 55000 }}; STATIC void attack(int, struct item *); STATIC void duck(int); STATIC void face_and_move_direction(int, int); STATIC int go_for_ammo(char); STATIC void ottolook(int, struct item *); STATIC void look_around(void); STATIC SIGNAL_TYPE nothing(int); STATIC int stop_look(struct item *, char, int, int); STATIC void wander(void); extern int Otto_count; STATIC SIGNAL_TYPE nothing(dummy) int dummy __attribute__((__unused__)); { } void otto(y, x, face) int y, x; char face; { int i; int old_mask; # ifdef DEBUG if (debug == NULL) { debug = fopen("bug", "w"); setbuf(debug, NULL); } fprintf(debug, "\n%c(%d,%d)", face, y, x); # endif (void) signal(SIGALRM, nothing); old_mask = sigblock(sigmask(SIGALRM)); setitimer(ITIMER_REAL, &pause_time, NULL); sigpause(old_mask); sigsetmask(old_mask); /* save away parameters so other functions may use/update info */ switch (face) { case '^': facing = NORTH; break; case '<': facing = WEST; break; case 'v': facing = SOUTH; break; case '>': facing = EAST; break; default: abort(); } row = y; col = x; been_there[row][col] |= 1 << facing; /* initially no commands to be sent */ comlen = 0; /* find something to do */ look_around(); for (i = 0; i < NUMDIRECTIONS; i++) { if (strchr(OPPONENT, flbr[i].what) != NULL) { attack(i, &flbr[i]); memset(been_there, 0, sizeof been_there); goto done; } } if (strchr(SHOTS, bitem.what) != NULL && !(bitem.what & ON_SIDE)) { duck(BACK); memset(been_there, 0, sizeof been_there); # ifdef BOOTS } else if (go_for_ammo(BOOT_PAIR)) { memset(been_there, 0, sizeof been_there); } else if (go_for_ammo(BOOT)) { memset(been_there, 0, sizeof been_there); # endif } else if (go_for_ammo(GMINE)) memset(been_there, 0, sizeof been_there); else if (go_for_ammo(MINE)) memset(been_there, 0, sizeof been_there); else wander(); done: (void) write(Socket, command, comlen); Otto_count += comlen; # ifdef DEBUG (void) fwrite(command, 1, comlen, debug); # endif } # define direction(abs,rel) (((abs) + (rel)) % NUMDIRECTIONS) STATIC int stop_look(itemp, c, dist, side) struct item *itemp; char c; int dist; int side; { switch (c) { case SPACE: if (side) itemp->flags &= ~DEADEND; return 0; case MINE: case GMINE: # ifdef BOOTS case BOOT: case BOOT_PAIR: # endif if (itemp->distance == -1) { itemp->distance = dist; itemp->what = c; if (side < 0) itemp->flags |= ON_LEFT; else if (side > 0) itemp->flags |= ON_RIGHT; } return 0; case SHOT: case GRENADE: case SATCHEL: case BOMB: # ifdef OOZE case SLIME: # endif if (itemp->distance == -1 || (!side && (itemp->flags & ON_SIDE || itemp->what == GMINE || itemp->what == MINE))) { itemp->distance = dist; itemp->what = c; itemp->flags &= ~ON_SIDE; if (side < 0) itemp->flags |= ON_LEFT; else if (side > 0) itemp->flags |= ON_RIGHT; } return 0; case '{': case '}': case 'i': case '!': itemp->distance = dist; itemp->what = c; itemp->flags &= ~(ON_SIDE|DEADEND); if (side < 0) itemp->flags |= ON_LEFT; else if (side > 0) itemp->flags |= ON_RIGHT; return 1; default: /* a wall or unknown object */ if (side) return 0; if (itemp->distance == -1) { itemp->distance = dist; itemp->what = c; } return 1; } } STATIC void ottolook(rel_dir, itemp) int rel_dir; struct item *itemp; { int r, c; char ch; r = 0; itemp->what = 0; itemp->distance = -1; itemp->flags = DEADEND|BEEN; /* true until proven false */ switch (direction(facing, rel_dir)) { case NORTH: if (been_there[row - 1][col] & NORTH) itemp->flags |= BEEN_SAME; for (r = row - 1; r >= 0; r--) for (c = col - 1; c < col + 2; c++) { ch = SCREEN(r, c); if (stop_look(itemp, ch, row - r, c - col)) goto cont_north; if (c == col && !been_there[r][c]) itemp->flags &= ~BEEN; } cont_north: if (itemp->flags & DEADEND) { itemp->flags |= BEEN; been_there[r][col] |= NORTH; for (r = row - 1; r > row - itemp->distance; r--) been_there[r][col] = ALLDIRS; } break; case SOUTH: if (been_there[row + 1][col] & SOUTH) itemp->flags |= BEEN_SAME; for (r = row + 1; r < HEIGHT; r++) for (c = col - 1; c < col + 2; c++) { ch = SCREEN(r, c); if (stop_look(itemp, ch, r - row, col - c)) goto cont_south; if (c == col && !been_there[r][c]) itemp->flags &= ~BEEN; } cont_south: if (itemp->flags & DEADEND) { itemp->flags |= BEEN; been_there[r][col] |= SOUTH; for (r = row + 1; r < row + itemp->distance; r++) been_there[r][col] = ALLDIRS; } break; case WEST: if (been_there[row][col - 1] & WEST) itemp->flags |= BEEN_SAME; for (c = col - 1; c >= 0; c--) for (r = row - 1; r < row + 2; r++) { ch = SCREEN(r, c); if (stop_look(itemp, ch, col - c, row - r)) goto cont_west; if (r == row && !been_there[r][c]) itemp->flags &= ~BEEN; } cont_west: if (itemp->flags & DEADEND) { itemp->flags |= BEEN; been_there[r][col] |= WEST; for (c = col - 1; c > col - itemp->distance; c--) been_there[row][c] = ALLDIRS; } break; case EAST: if (been_there[row][col + 1] & EAST) itemp->flags |= BEEN_SAME; for (c = col + 1; c < WIDTH; c++) for (r = row - 1; r < row + 2; r++) { ch = SCREEN(r, c); if (stop_look(itemp, ch, c - col, r - row)) goto cont_east; if (r == row && !been_there[r][c]) itemp->flags &= ~BEEN; } cont_east: if (itemp->flags & DEADEND) { itemp->flags |= BEEN; been_there[r][col] |= EAST; for (c = col + 1; c < col + itemp->distance; c++) been_there[row][c] = ALLDIRS; } break; default: abort(); } } STATIC void look_around() { int i; for (i = 0; i < NUMDIRECTIONS; i++) { ottolook(i, &flbr[i]); # ifdef DEBUG fprintf(debug, " ottolook(%c)=%c(%d)(0x%x)", RELCHARS[i], flbr[i].what, flbr[i].distance, flbr[i].flags); # endif } } /* * as a side effect modifies facing and location (row, col) */ STATIC void face_and_move_direction(rel_dir, distance) int rel_dir, distance; { int old_facing; char cmd; old_facing = facing; cmd = DIRKEYS[facing = direction(facing, rel_dir)]; if (rel_dir != FRONT) { int i; struct item items[NUMDIRECTIONS]; command[comlen++] = toupper((unsigned char)cmd); if (distance == 0) { /* rotate ottolook's to be in right position */ for (i = 0; i < NUMDIRECTIONS; i++) items[i] = flbr[(i + old_facing) % NUMDIRECTIONS]; memcpy(flbr, items, sizeof flbr); } } while (distance--) { command[comlen++] = cmd; switch (facing) { case NORTH: row--; break; case WEST: col--; break; case SOUTH: row++; break; case EAST: col++; break; } if (distance == 0) look_around(); } } STATIC void attack(rel_dir, itemp) int rel_dir; struct item *itemp; { if (!(itemp->flags & ON_SIDE)) { face_and_move_direction(rel_dir, 0); command[comlen++] = 'o'; command[comlen++] = 'o'; duck(FRONT); command[comlen++] = ' '; } else if (itemp->distance > 1) { face_and_move_direction(rel_dir, 2); duck(FRONT); } else { face_and_move_direction(rel_dir, 1); if (itemp->flags & ON_LEFT) rel_dir = LEFT; else rel_dir = RIGHT; (void) face_and_move_direction(rel_dir, 0); command[comlen++] = 'f'; command[comlen++] = 'f'; duck(FRONT); command[comlen++] = ' '; } } STATIC void duck(rel_dir) int rel_dir; { int dir; switch (dir = direction(facing, rel_dir)) { case NORTH: case SOUTH: if (strchr(PUSHOVER, SCREEN(row, col - 1)) != NULL) command[comlen++] = 'h'; else if (strchr(PUSHOVER, SCREEN(row, col + 1)) != NULL) command[comlen++] = 'l'; else if (dir == NORTH && strchr(PUSHOVER, SCREEN(row + 1, col)) != NULL) command[comlen++] = 'j'; else if (dir == SOUTH && strchr(PUSHOVER, SCREEN(row - 1, col)) != NULL) command[comlen++] = 'k'; else if (dir == NORTH) command[comlen++] = 'k'; else command[comlen++] = 'j'; break; case WEST: case EAST: if (strchr(PUSHOVER, SCREEN(row - 1, col)) != NULL) command[comlen++] = 'k'; else if (strchr(PUSHOVER, SCREEN(row + 1, col)) != NULL) command[comlen++] = 'j'; else if (dir == WEST && strchr(PUSHOVER, SCREEN(row, col + 1)) != NULL) command[comlen++] = 'l'; else if (dir == EAST && strchr(PUSHOVER, SCREEN(row, col - 1)) != NULL) command[comlen++] = 'h'; else if (dir == WEST) command[comlen++] = 'h'; else command[comlen++] = 'l'; break; } } /* * go for the closest mine if possible */ STATIC int go_for_ammo(mine) char mine; { int i, rel_dir, dist; rel_dir = -1; dist = WIDTH; for (i = 0; i < NUMDIRECTIONS; i++) { if (flbr[i].what == mine && flbr[i].distance < dist) { rel_dir = i; dist = flbr[i].distance; } } if (rel_dir == -1) return FALSE; if (!(flbr[rel_dir].flags & ON_SIDE) || flbr[rel_dir].distance > 1) { if (dist > 4) dist = 4; face_and_move_direction(rel_dir, dist); } else return FALSE; /* until it's done right */ return TRUE; } STATIC void wander() { int i, j, rel_dir, dir_mask, dir_count; for (i = 0; i < NUMDIRECTIONS; i++) if (!(flbr[i].flags & BEEN) || flbr[i].distance <= 1) break; if (i == NUMDIRECTIONS) memset(been_there, 0, sizeof been_there); dir_mask = dir_count = 0; for (i = 0; i < NUMDIRECTIONS; i++) { j = (RIGHT + i) % NUMDIRECTIONS; if (flbr[j].distance <= 1 || flbr[j].flags & DEADEND) continue; if (!(flbr[j].flags & BEEN_SAME)) { dir_mask = 1 << j; dir_count = 1; break; } if (j == FRONT && num_turns > 4 + (random() % ((flbr[FRONT].flags & BEEN) ? 7 : HEIGHT))) continue; dir_mask |= 1 << j; # ifdef notdef dir_count++; # else dir_count = 1; break; # endif } if (dir_count == 0) { duck(random() % NUMDIRECTIONS); num_turns = 0; return; } else if (dir_count == 1) rel_dir = ffs(dir_mask) - 1; else { rel_dir = ffs(dir_mask) - 1; dir_mask &= ~(1 << rel_dir); while (dir_mask != 0) { i = ffs(dir_mask) - 1; if (random() % 5 == 0) rel_dir = i; dir_mask &= ~(1 << i); } } if (rel_dir == FRONT) num_turns++; else num_turns = 0; # ifdef DEBUG fprintf(debug, " w(%c)", RELCHARS[rel_dir]); # endif face_and_move_direction(rel_dir, 1); } # endif /* OTTO */
the_stack_data/926879.c
#ifdef PS2PLUS_FIRMWARE #include "../command.h" const uint8_t DD47_CONSTANT_BYTES[5] = { 0x00, 0x02, 0x00, 0x01, 0x00 }; command_result dd47_initialize(volatile command_packet *packet, controller_state *state) { // No initialization or memory state management needed return CRInitialized; } command_result dd47_process(volatile command_packet *packet, controller_state *state) { if (packet->data_index == 0) { packet->write(0x00); } else { packet->write(DD47_CONSTANT_BYTES[packet->data_index - 1]); } // If the final byte hasn't been written, mark this command as still processing if (packet->data_index + 1 != 6) { return CRProcessing; } return CRCompleted; } command_processor command_controller_device_descriptor_47 = { .id = 0x47, .initialize = &dd47_initialize, .process = &dd47_process, }; #endif
the_stack_data/1183901.c
// #include "unity.h" // #include "../../src/common/hk_conn_key_store.h" // #include "../../src/common/hk_pair_tlvs.h" // #include "../../src/common/hk_pairings_store.h" // #include "../../src/crypto/hk_ed25519.h" // #include "../../src/crypto/hk_curve25519.h" // #include "../../src/crypto/hk_hkdf.h" // #include "../../src/crypto/hk_chacha20poly1305.h" // #include "../../src/utils/hk_tlv.h" // #include "../../src/utils/hk_store.h" // #include "../../src/utils/hk_logging.h" // #include "hk_pair_verify_test_vectors.h" // esp_err_t hk_pair_verify_start(hk_conn_key_store_t *keys, hk_tlv_t *request_tlvs, hk_tlv_t **response_tlvs_ptr); // esp_err_t hk_pair_verify_finish(hk_conn_key_store_t *keys, hk_tlv_t *request_tlvs, hk_tlv_t **response_tlvs_ptr); // void hk_pair_verify_device_m1(hk_tlv_t **response_tlvs_ptr, hk_curve25519_key_t *device_session_key); // void hk_pair_verify_device_m3(hk_tlv_t *request_tlvs, hk_tlv_t **response_tlvs_ptr, // hk_curve25519_key_t *device_session_key, hk_ed25519_key_t *device_long_term_key); // TEST_CASE("verify once", "[pair] [verify]") // { // // prepare // hk_tlv_t *m1_tlvs = NULL; // hk_tlv_t *m2_tlvs = NULL; // hk_tlv_t *m3_tlvs = NULL; // hk_tlv_t *m4_tlvs = NULL; // hk_tlv_t *m12_tlvs = NULL; // hk_tlv_t *m22_tlvs = NULL; // hk_tlv_t *m32_tlvs = NULL; // hk_tlv_t *m42_tlvs = NULL; // hk_conn_key_store_t *keys = hk_conn_key_store_init(); // hk_curve25519_key_t *device_session_key = hk_curve25519_init(); // hk_ed25519_key_t *device_long_term_key = hk_ed25519_init(); // hk_ed25519_init_from_random(device_long_term_key); // hk_mem *device_long_term_key_public = hk_mem_init(); // hk_ed25519_export_public_key(device_long_term_key, device_long_term_key_public); // hk_mem *device_id = hk_mem_init(); // hk_mem_append_string(device_id, device_id_string); // hk_mem *accessory_public_key = hk_mem_init(); // hk_mem_append_buffer(accessory_public_key, (void *)hk_pair_verify_test_accessory_ltpk_bytes, sizeof(hk_pair_verify_test_accessory_ltpk_bytes)); // hk_mem *accessory_private_key = hk_mem_init(); // hk_mem_append_buffer(accessory_private_key, (void *)accessory_private_key_bytes, sizeof(accessory_private_key_bytes)); // hk_store_init(); // hk_pairings_store_remove_all(); // hk_key_store_pub_set(accessory_public_key); // hk_key_store_priv_set(accessory_private_key); // hk_pairings_store_add(device_id, device_long_term_key_public, true); // // test // hk_pair_verify_device_m1(&m1_tlvs, device_session_key); // esp_err_t ret1 = hk_pair_verify_start(keys, m1_tlvs, &m2_tlvs); // hk_pair_verify_device_m3(m2_tlvs, &m3_tlvs, device_session_key, device_long_term_key); // esp_err_t ret2 = hk_pair_verify_finish(keys, m3_tlvs, &m4_tlvs); // hk_pair_verify_device_m1(&m12_tlvs, device_session_key); // esp_err_t ret12 = hk_pair_verify_start(keys, m12_tlvs, &m22_tlvs); // hk_pair_verify_device_m3(m22_tlvs, &m32_tlvs, device_session_key, device_long_term_key); // esp_err_t ret22 = hk_pair_verify_finish(keys, m32_tlvs, &m42_tlvs); // // assert // TEST_ASSERT_EQUAL(ESP_OK, ret1); // TEST_ASSERT_EQUAL(ESP_OK, ret2); // TEST_ASSERT_EQUAL(ESP_OK, ret12); // TEST_ASSERT_EQUAL(ESP_OK, ret22); // // cleanup // hk_tlv_free(m1_tlvs); // hk_tlv_free(m2_tlvs); // hk_tlv_free(m3_tlvs); // hk_tlv_free(m4_tlvs); // hk_conn_key_store_free(keys); // hk_store_free(); // hk_mem_free(accessory_public_key); // hk_mem_free(accessory_private_key); // hk_curve25519_free(device_session_key); // hk_ed25519_free(device_long_term_key); // hk_mem_free(device_id); // hk_mem_free(device_long_term_key_public); // } // void hk_pair_verify_device_m1(hk_tlv_t **response_tlvs_ptr, hk_curve25519_key_t *device_session_key) // { // hk_tlv_t *response_tlvs = NULL; // hk_mem *device_session_key_public = hk_mem_init(); // TEST_ASSERT_EQUAL(ESP_OK, hk_curve25519_update_from_random(device_session_key)); // TEST_ASSERT_EQUAL(ESP_OK, hk_curve25519_export_public_key(device_session_key, device_session_key_public)); // response_tlvs = hk_tlv_add_uint8(response_tlvs, HK_PAIR_TLV_STATE, HK_PAIR_TLV_STATE_M2); // response_tlvs = hk_tlv_add_mem(response_tlvs, HK_PAIR_TLV_PUBLICKEY, device_session_key_public); // *response_tlvs_ptr = response_tlvs; // hk_mem_free(device_session_key_public); // } // void hk_pair_verify_device_m3(hk_tlv_t *request_tlvs, hk_tlv_t **response_tlvs_ptr, // hk_curve25519_key_t *device_session_key, hk_ed25519_key_t *device_long_term_key) // { // hk_tlv_t *response_tlvs = NULL; // hk_curve25519_key_t *accessory_session_key = hk_curve25519_init(); // hk_ed25519_key_t *accessory_long_term_key = hk_ed25519_init(); // hk_mem *accessory_session_key_public = hk_mem_init(); // hk_mem *accessory_id = hk_mem_init(); // hk_mem *accessory_long_term_public_key = hk_mem_init(); // hk_mem_append_buffer(accessory_long_term_public_key, (void *)hk_pair_verify_test_accessory_ltpk_bytes, // sizeof(hk_pair_verify_test_accessory_ltpk_bytes)); // hk_mem *device_session_key_public = hk_mem_init(); // hk_curve25519_export_public_key(device_session_key, device_session_key_public); // hk_mem *device_id = hk_mem_init(); // hk_mem_append_string(device_id, device_id_string); // hk_mem *shared_secret = hk_mem_init(); // hk_mem *encrypted_data = hk_mem_init(); // hk_mem *decrypted_data = hk_mem_init(); // hk_mem *session_encryption_key = hk_mem_init(); // hk_mem *device_info = hk_mem_init(); // hk_mem *device_signature = hk_mem_init(); // hk_mem *sub_result = hk_mem_init(); // hk_tlv_t *request_sub_tlvs = NULL; // hk_tlv_t *response_sub_tlvs = NULL; // TEST_ASSERT_EQUAL(ESP_OK, hk_tlv_get_mem_by_type(request_tlvs, HK_PAIR_TLV_PUBLICKEY, accessory_session_key_public)); // TEST_ASSERT_EQUAL(ESP_OK, hk_tlv_get_mem_by_type(request_tlvs, HK_PAIR_TLV_ENCRYPTEDDATA, encrypted_data)); // TEST_ASSERT_EQUAL(ESP_OK, hk_curve25519_update_from_public_key(accessory_session_key_public, accessory_session_key)); // TEST_ASSERT_EQUAL(ESP_OK, hk_curve25519_calculate_shared_secret(device_session_key, accessory_session_key, shared_secret)); // TEST_ASSERT_EQUAL(ESP_OK, hk_hkdf(shared_secret, session_encryption_key, HK_HKDF_PAIR_VERIFY_ENCRYPT_SALT, HK_HKDF_PAIR_VERIFY_ENCRYPT_INFO)); // TEST_ASSERT_EQUAL(ESP_OK, hk_chacha20poly1305_decrypt(session_encryption_key, HK_CHACHA_VERIFY_MSG2, encrypted_data, decrypted_data)); // request_sub_tlvs = hk_tlv_deserialize(decrypted_data); // TEST_ASSERT_EQUAL(ESP_OK, hk_tlv_get_mem_by_type(request_sub_tlvs, HK_PAIR_TLV_IDENTIFIER, accessory_id)); // TEST_ASSERT_EQUAL(ESP_OK, hk_ed25519_init_from_public_key(accessory_long_term_key, accessory_long_term_public_key)); // hk_mem_append(device_info, device_session_key_public); // hk_mem_append(device_info, device_id); // hk_mem_append(device_info, accessory_session_key_public); // TEST_ASSERT_EQUAL(ESP_OK, hk_ed25519_sign(device_long_term_key, device_info, device_signature)); // response_sub_tlvs = hk_tlv_add_mem(response_sub_tlvs, HK_PAIR_TLV_IDENTIFIER, device_id); // response_sub_tlvs = hk_tlv_add_mem(response_sub_tlvs, HK_PAIR_TLV_SIGNATURE, device_signature); // hk_tlv_serialize(response_sub_tlvs, sub_result); // hk_mem_set(encrypted_data, 0); // TEST_ASSERT_EQUAL(ESP_OK, hk_chacha20poly1305_encrypt(session_encryption_key, HK_CHACHA_VERIFY_MSG3, sub_result, encrypted_data)); // response_tlvs = hk_tlv_add_uint8(response_tlvs, HK_PAIR_TLV_STATE, HK_PAIR_TLV_STATE_M3); // response_tlvs = hk_tlv_add_mem(response_tlvs, HK_PAIR_TLV_ENCRYPTEDDATA, encrypted_data); // *response_tlvs_ptr = response_tlvs; // hk_curve25519_free(accessory_session_key); // hk_ed25519_free(accessory_long_term_key); // hk_mem_free(accessory_long_term_public_key); // hk_mem_free(accessory_session_key_public); // hk_mem_free(accessory_id); // hk_mem_free(device_id); // hk_mem_free(device_session_key_public); // hk_mem_free(shared_secret); // hk_mem_free(session_encryption_key); // hk_mem_free(encrypted_data); // hk_mem_free(decrypted_data); // hk_mem_free(device_info); // hk_mem_free(device_signature); // hk_mem_free(sub_result); // hk_tlv_free(request_sub_tlvs); // hk_tlv_free(response_sub_tlvs); // }
the_stack_data/12638013.c
//@ #include "raw_ghost_lists.gh" int main() //@ : main //@ requires true; //@ ensures true; { //@ create_raw_ghost_list(); *((int *)0) = 5; return 0; }
the_stack_data/70451184.c
/*----------------------------------------------------------- -- bramtest.c -- -- FPGA BRAM testing program -- -- Copyright: Daniel Tisza, 2022, GPLv3 or later -----------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include <stdint.h> int main() { off_t bram_pbase = 0x81000000; unsigned int bram_size = 0x8000; uint32_t * bram_vptr; int fd; if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) != -1) { bram_vptr = (uint32_t *)mmap( NULL, bram_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, bram_pbase ); //Read from BRAM located in FPGA //Current FPGA pixel processor writes value 0x1234ABCD to this location printf("\r\n"); printf("Reading value from FPGA shared BRAM at address 0x0: %X\r\n", bram_vptr[0]); //Test writing to BRAM located in FPGA //Write to BRAM located in FPGA printf("\r\n"); printf("Writing value 0xAABBCCDD to FPGA shared BRAM at address 0x1\r\n"); bram_vptr[1] = 0xAABBCCDD; //Read back data written to BRAM located in FPGA printf("\r\n"); printf("Reading back value 0xAABBCCDD from FPGA shared BRAM at address 0x1%X\r\n", bram_vptr[1]); printf("\r\n"); close(fd); } }