Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
2afe144e7f | |||
a988711918 | |||
74a82e2038 | |||
659bdeee27 | |||
d39a51baa2 |
@ -1,3 +1,19 @@
|
|||||||
|
# Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
# Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
project(Indivisible)
|
project(Indivisible)
|
||||||
|
|
||||||
@ -6,8 +22,10 @@ cmake_policy(SET CMP0012 OLD)
|
|||||||
set(TARGET_NAME indivisible)
|
set(TARGET_NAME indivisible)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE "debug")
|
||||||
endif()
|
endif()
|
||||||
|
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
|
||||||
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH
|
set(CMAKE_MODULE_PATH
|
||||||
${CMAKE_MODULE_PATH}
|
${CMAKE_MODULE_PATH}
|
||||||
@ -31,11 +49,14 @@ set(CMAKE_C_FLAGS_RELEASE "-O3")
|
|||||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3")
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3")
|
||||||
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
|
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE MATCHES Debug AND NOT CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
if(NOT CMAKE_BUILD_TYPE MATCHES "debug" AND NOT CMAKE_BUILD_TYPE MATCHES "relwithdebinfo")
|
||||||
add_definitions(-DNDEBUG)
|
add_definitions("-DNDEBUG")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(${TARGET_NAME} ${SRCS})
|
add_executable(${TARGET_NAME} ${SRCS})
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME}
|
target_link_libraries(${TARGET_NAME}
|
||||||
${GMP_LIBRARY})
|
${GMP_LIBRARY})
|
||||||
|
|
||||||
|
install(TARGETS ${TARGET_NAME}
|
||||||
|
RUNTIME DESTINATION "bin")
|
||||||
|
24
src/files.c
24
src/files.c
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
@ -33,9 +51,9 @@ int outputPrimes(char *file, List *list, size_t startPos) {
|
|||||||
puts("0%");
|
puts("0%");
|
||||||
for(size_t i = startPos; i < list->end; ++i) {
|
for(size_t i = startPos; i < list->end; ++i) {
|
||||||
if(!mpz_out_raw(out, list->list[i])) return 3;
|
if(!mpz_out_raw(out, list->list[i])) return 3;
|
||||||
if(i == list->end / 4) puts("25%");
|
if(i - startPos == (list->end - startPos) / 4) puts("25%");
|
||||||
else if(i == list->end / 2) puts("50%");
|
else if(i - startPos == (list->end - startPos) / 2) puts("50%");
|
||||||
else if(i == list->end * 3 / 4) puts("75%");
|
else if(i - startPos == (list->end - startPos) * 3 / 4) puts("75%");
|
||||||
}
|
}
|
||||||
puts("100%");
|
puts("100%");
|
||||||
|
|
||||||
|
18
src/files.h
18
src/files.h
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file files.h
|
* @file files.h
|
||||||
* @author Deathsbreed <deathsbreed@themusicinnoise.net>
|
* @author Deathsbreed <deathsbreed@themusicinnoise.net>
|
||||||
|
18
src/list.c
18
src/list.c
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
18
src/list.h
18
src/list.h
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file list.h
|
* @file list.h
|
||||||
* @author Deathsbreed <deathsbreed@themusicinnoise.net>
|
* @author Deathsbreed <deathsbreed@themusicinnoise.net>
|
||||||
|
26
src/main.c
26
src/main.c
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
* Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -96,7 +114,13 @@ int main(int argc, char *argv[]) {
|
|||||||
printUsage(argv[0]);
|
printUsage(argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
} else if(efile && dfile) {
|
} else if(efile && dfile) {
|
||||||
exportPrimes(efile, dfile, base);
|
int err = exportPrimes(efile, dfile, base);
|
||||||
|
if(err) {
|
||||||
|
if(err == 1) fprintf(stderr, "Error: failed to open files.\n");
|
||||||
|
else if(err == 2) fprintf(stderr, "Error: failed to close files.\n");
|
||||||
|
else if(err == 3) fprintf(stderr, "Error: failed to write to export file.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user