Skip to content
Snippets Groups Projects
Commit c8587a04 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Fix the reading of multiple parameters via pipes

parent 2df183b6
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,6 @@ blc_channel::blc_channel(char const *new_name, int mode):access_mode{mode}, fd{-
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const dims[BLC_ARRAY_DIMS_MAX]):access_mode{mode}, fd{-1}, sem_new_data{nullptr}, sem_ack_data{nullptr}, parameter{"NDEF"}{
create_or_open(new_name, access_mode, type, format, dims_nb, dims);
}
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, vector<size_t> lengths ):blc_channel(){
int id, created;
uint32_t new_type_str, new_format_str;
......@@ -456,8 +455,12 @@ int blc_channel::create_or_open(char const *new_name, int access_mode, uint32_t
int blc_channel::create_or_open(char const *new_name, int access_mode, uint32_t type, uint32_t format, vector<size_t> const &lengths){
int dims_nb = lengths.size();
blc_dim dims[BLC_ARRAY_DIMS_MAX];
for (int i; i!=dims_nb; i++) {
size=blc_get_type_size(type);
for (int i=0; i!=dims_nb; i++) {
dims[i].length=lengths[i];
dims[i].step=size;
size*=lengths[i];
}
return create_or_open(new_name, access_mode, type, format, dims_nb, dims);
}
......
......@@ -6,16 +6,17 @@
This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured
and, more generally, to use and operate it in the same conditions as regards security.
The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */
and, more generally, to use and operate it in the same conditions as regards security.
The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */
#include "blc_program.h"
#include "program.hpp" // internal to blc
#include <sys/time.h>
#include <iostream> //std::getline
#include <stdio.h>
#include <sys/ioctl.h>
......@@ -319,9 +320,8 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
break;
case STRING_LIST:
missing_parameters_nb = abs(program_parameter.required_nb)-(*argc);
if (isatty(STDIN_FILENO)) {
missing_parameters_nb = abs(program_parameter.required_nb)-(*argc);
if (missing_parameters_nb>0){
FOR(i, missing_parameters_nb){
fprintf(stderr, "%s: %s(%d) ? ", program_parameter.help, program_parameter.name, i);
......@@ -335,23 +335,24 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
}
}
else {
do{
parameter_read=getline(&tmp_parameter, &linecap, stdin);
if (parameter_read==-1){
FOR(i, missing_parameters_nb){
string tmp_string;
getline(cin, tmp_string);
if (cin.bad()){
if (errno==ENOTTY) {
color_eprintf(BLC_RED, "Quitting '%s': The standard input is not available. You probably have a program on an input pipe which has crashed\n", blc_program_id);
exit(1);
}
else EXIT_ON_SYSTEM_ERROR("Reading input for parameter");
}
tmp_parameter[parameter_read-1]=0;//Remove the last return;
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_parameter);
linecap=0;
tmp_parameter=nullptr;
fprintf(stderr, "Parameters '%s' %ld\n", tmp_parameter, parameter_read );
tmp_string.c_str();
tmp_arg = strndup(tmp_string.data(), tmp_string.length() ); //remove the copy and remove last return
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_arg);
}
while(parameter_read>0);
}
if (program_parameter.required_nb<=0 ){
while((*argc)){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment