Exemplo n.º 1
0
char * read_cmd() {
    /*
     * funkcja odczytuje komende
     */
    int cmd_size = MAX_INPUT_LEN;
    int position = 0;
    char *cmd = malloc(sizeof(char) * cmd_size);
    int c;

    if (!cmd) {
        alloc_error();
    }

    while (1) {
        c = getchar();
        if (c == EOF || c == '\n') {
            cmd[position] = '\0';
            return cmd;
        } else {
            cmd[position] = c;
        }
        position++;
        if (position >= cmd_size) {
            cmd_size += MAX_INPUT_LEN;
            cmd = realloc(cmd, cmd_size);
            if (!cmd) {
                alloc_error();
            }
        }
    }


}
Exemplo n.º 2
0
Arquivo: error.c Projeto: bilboed/wine
static HRESULT create_error(script_ctx_t *ctx, DispatchEx *constr,
        const UINT *number, const WCHAR *msg, DispatchEx **ret)
{
    ErrorInstance *err;
    HRESULT hres;

    hres = alloc_error(ctx, NULL, constr, &err);
    if(FAILED(hres))
        return hres;

    if(number) {
        V_VT(&err->number) = VT_I4;
        V_I4(&err->number) = *number;
    }

    V_VT(&err->message) = VT_BSTR;
    if(msg) V_BSTR(&err->message) = SysAllocString(msg);
    else V_BSTR(&err->message) = SysAllocStringLen(NULL, 0);

    VariantCopy(&err->description, &err->message);

    if(!V_BSTR(&err->message)) {
        heap_free(err);
        return E_OUTOFMEMORY;
    }

    *ret = &err->dispex;
    return S_OK;
}
Exemplo n.º 3
0
static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr,
        UINT number, jsstr_t *msg, jsdisp_t **ret)
{
    jsdisp_t *err;
    HRESULT hres;

    hres = alloc_error(ctx, NULL, constr, &err);
    if(FAILED(hres))
        return hres;

    hres = jsdisp_propput_dontenum(err, numberW, jsval_number((INT)number));
    if(FAILED(hres)) {
        jsdisp_release(err);
        return hres;
    }

    hres = jsdisp_propput_name(err, messageW, jsval_string(msg));
    if(SUCCEEDED(hres))
        hres = jsdisp_propput_dontenum(err, descriptionW, jsval_string(msg));
    if(FAILED(hres)) {
        jsdisp_release(err);
        return hres;
    }

    *ret = err;
    return S_OK;
}
Exemplo n.º 4
0
    void expand_buffer(size_t len)
    {
        size_t nsize = (_alloc > 0) ?
                    _alloc * 2 : 8192;

        while(nsize < _size + len)
        {
            size_t tmp_nsize = nsize * 2;
            if (tmp_nsize <= nsize)
            {
                nsize = _size + len;
                break;
            }
            nsize = tmp_nsize;
        }

        void* tmp = realloc(_data, nsize);
        if(!tmp)
        {
            throw alloc_error();
        }

        _data = static_cast<char*>(tmp);
        _alloc = nsize;
    }
Exemplo n.º 5
0
UaNodeId::UaNodeId ( const UaNodeId & other)
{
    UA_NodeId_init( &m_impl );
    UA_StatusCode status = UA_NodeId_copy( other.pimpl(), &this->m_impl );
    if (status != UA_STATUSCODE_GOOD)
        throw alloc_error();

}
Exemplo n.º 6
0
const UaNodeId& UaNodeId::operator=(const UaNodeId & other)
{
    UA_NodeId_deleteMembers( &m_impl );
    UA_NodeId_init( &m_impl );
    UA_StatusCode status = UA_NodeId_copy( other.pimpl(), &this->m_impl );
    if (status != UA_STATUSCODE_GOOD)
        throw alloc_error();
    return *this;
}
Exemplo n.º 7
0
void UaNodeId::copyTo( UA_NodeId* other) const
{
    if (!other)
        throw std::runtime_error("passed a nullptr");
    UA_StatusCode status = UA_NodeId_copy( &this->m_impl, other );
    if (status != UA_STATUSCODE_GOOD)
        throw alloc_error();

}
Exemplo n.º 8
0
UaNodeId::UaNodeId ( const UaString& stringAddress, int ns)
{
    // TODO: not implemented yet in open62541
    //    UA_NodeId_fromInteger( 2, 2);
    m_impl.namespaceIndex = ns;
    m_impl.identifierType = UA_NODEIDTYPE_STRING;
    UA_StatusCode status = UA_String_copy( stringAddress.impl(), &m_impl.identifier.string );
    if (status != UA_STATUSCODE_GOOD)
        throw alloc_error();
}
Exemplo n.º 9
0
/**
 * Allocates, initializes and returns a new couple.
 */
struct couple* new_couple(unichar* s) {
  struct couple* c = (struct couple*) malloc(sizeof(struct couple));
  if (c == NULL) {
    alloc_error("new_couple");
    return NULL;
  }
  c->next = NULL;
  c->n = 1;
  c->s = u_strdup(s);
  return c;
}
Exemplo n.º 10
0
/**
 * Initializes, allocates and returns a new sort tree node.
 */
struct sort_tree_node* new_sort_tree_node() {
  struct sort_tree_node* n = (struct sort_tree_node*) malloc(
      sizeof(struct sort_tree_node));
  if (n == NULL) {
    alloc_error("new_sort_tree_node");
    return NULL;
  }
  n->couples = NULL;
  n->transitions = NULL;
  return n;
}
Exemplo n.º 11
0
/**
 * Initializes, allocates and returns a new sort tree transition.
 */
struct sort_tree_transition* new_sort_tree_transition() {
  struct sort_tree_transition* t = (struct sort_tree_transition*) malloc(
      sizeof(struct sort_tree_transition));
  if (t == NULL) {
    alloc_error("new_sort_tree_transition");
    return NULL;
  }
  t->node = NULL;
  t->next = NULL;
  return t;
}
Exemplo n.º 12
0
/**
* display the copyright notice
*/
void display_copyright_notice() {
  unichar* str = (unichar*)malloc(sizeof(unichar) * (SIZE_COPYRIGHT_NOTICE_BUFFER));
  if (str == NULL) {
    alloc_error("display_copyright_notice");
    return;
  }

  convert_utf8_to_unichar(str, SIZE_COPYRIGHT_NOTICE_BUFFER - 1, NULL, (const unsigned char*)get_copyright_utf8(), strlen(get_copyright_utf8()) + 1);

  u_printf("%S", str);
  free(str);
}
Exemplo n.º 13
0
Arquivo: error.c Projeto: bilboed/wine
HRESULT init_error_constr(script_ctx_t *ctx, DispatchEx *object_prototype)
{
    static const WCHAR ErrorW[] = {'E','r','r','o','r',0};
    static const WCHAR EvalErrorW[] = {'E','v','a','l','E','r','r','o','r',0};
    static const WCHAR RangeErrorW[] = {'R','a','n','g','e','E','r','r','o','r',0};
    static const WCHAR ReferenceErrorW[] = {'R','e','f','e','r','e','n','c','e','E','r','r','o','r',0};
    static const WCHAR RegExpErrorW[] = {'R','e','g','E','x','p','E','r','r','o','r',0};
    static const WCHAR SyntaxErrorW[] = {'S','y','n','t','a','x','E','r','r','o','r',0};
    static const WCHAR TypeErrorW[] = {'T','y','p','e','E','r','r','o','r',0};
    static const WCHAR URIErrorW[] = {'U','R','I','E','r','r','o','r',0};
    static const WCHAR *names[] = {ErrorW, EvalErrorW, RangeErrorW,
        ReferenceErrorW, RegExpErrorW, SyntaxErrorW, TypeErrorW, URIErrorW};
    DispatchEx **constr_addr[] = {&ctx->error_constr, &ctx->eval_error_constr,
        &ctx->range_error_constr, &ctx->reference_error_constr, &ctx->regexp_error_constr,
        &ctx->syntax_error_constr, &ctx->type_error_constr,
        &ctx->uri_error_constr};
    static builtin_invoke_t constr_val[] = {ErrorConstr_value, EvalErrorConstr_value,
        RangeErrorConstr_value, ReferenceErrorConstr_value, RegExpErrorConstr_value,
        SyntaxErrorConstr_value, TypeErrorConstr_value, URIErrorConstr_value};

    ErrorInstance *err;
    INT i;
    VARIANT v;
    HRESULT hres;

    for(i=0; i < sizeof(names)/sizeof(names[0]); i++) {
        hres = alloc_error(ctx, i==0 ? object_prototype : NULL, NULL, &err);
        if(FAILED(hres))
            return hres;

        V_VT(&v) = VT_BSTR;
        V_BSTR(&v) = SysAllocString(names[i]);
        if(!V_BSTR(&v)) {
            jsdisp_release(&err->dispex);
            return E_OUTOFMEMORY;
        }

        hres = jsdisp_propput_name(&err->dispex, nameW, &v, NULL/*FIXME*/, NULL/*FIXME*/);

        if(SUCCEEDED(hres))
            hres = create_builtin_function(ctx, constr_val[i], names[i], NULL,
                    PROPF_CONSTR|1, &err->dispex, constr_addr[i]);

        jsdisp_release(&err->dispex);
        VariantClear(&v);
        if(FAILED(hres))
            return hres;
    }

    return S_OK;
}
Exemplo n.º 14
0
HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
{
    static const WCHAR ErrorW[] = {'E','r','r','o','r',0};
    static const WCHAR EvalErrorW[] = {'E','v','a','l','E','r','r','o','r',0};
    static const WCHAR RangeErrorW[] = {'R','a','n','g','e','E','r','r','o','r',0};
    static const WCHAR ReferenceErrorW[] = {'R','e','f','e','r','e','n','c','e','E','r','r','o','r',0};
    static const WCHAR RegExpErrorW[] = {'R','e','g','E','x','p','E','r','r','o','r',0};
    static const WCHAR SyntaxErrorW[] = {'S','y','n','t','a','x','E','r','r','o','r',0};
    static const WCHAR TypeErrorW[] = {'T','y','p','e','E','r','r','o','r',0};
    static const WCHAR URIErrorW[] = {'U','R','I','E','r','r','o','r',0};
    static const WCHAR *names[] = {ErrorW, EvalErrorW, RangeErrorW,
        ReferenceErrorW, RegExpErrorW, SyntaxErrorW, TypeErrorW, URIErrorW};
    jsdisp_t **constr_addr[] = {&ctx->error_constr, &ctx->eval_error_constr,
        &ctx->range_error_constr, &ctx->reference_error_constr, &ctx->regexp_error_constr,
        &ctx->syntax_error_constr, &ctx->type_error_constr,
        &ctx->uri_error_constr};
    static builtin_invoke_t constr_val[] = {ErrorConstr_value, EvalErrorConstr_value,
        RangeErrorConstr_value, ReferenceErrorConstr_value, RegExpErrorConstr_value,
        SyntaxErrorConstr_value, TypeErrorConstr_value, URIErrorConstr_value};

    jsdisp_t *err;
    unsigned int i;
    jsstr_t *str;
    HRESULT hres;

    for(i=0; i < sizeof(names)/sizeof(names[0]); i++) {
        hres = alloc_error(ctx, i==0 ? object_prototype : NULL, NULL, &err);
        if(FAILED(hres))
            return hres;

        str = jsstr_alloc(names[i]);
        if(!str) {
            jsdisp_release(err);
            return E_OUTOFMEMORY;
        }

        hres = jsdisp_propput_dontenum(err, nameW, jsval_string(str));
        jsstr_release(str);
        if(SUCCEEDED(hres))
            hres = create_builtin_constructor(ctx, constr_val[i], names[i], NULL,
                    PROPF_CONSTR|1, err, constr_addr[i]);

        jsdisp_release(err);
        if(FAILED(hres))
            return hres;
    }

    return S_OK;
}
Exemplo n.º 15
0
    static void extract(const jsonpack::value &v, char* json_ptr, char* &value)
    {

        position p = v._pos;

        if(p._type != JTK_NULL)
        {
            value = (char*)malloc( p._count + 1) ;
            if(!value) throw alloc_error();
            memcpy( value, json_ptr + p._pos, p._count);
            value[p._count] = '\0';
        }
        else
        {
           value = nullptr;
        }

    }
Exemplo n.º 16
0
    buffer(size_t init_size = 8192)
        : _size(0),
          _data(nullptr),
          _alloc(init_size)

    {
        if(init_size == 0)
        {
            _data = nullptr;
        }
        else
        {
            _data = (char*) malloc(init_size);

            if(!_data)
            {
                throw alloc_error();
            }
        }
    }
Exemplo n.º 17
0
/**
 * Allocates, initializes and returns a new struct sort_infos*
 */
struct sort_infos* new_sort_infos() {
  struct sort_infos* inf = (struct sort_infos*) malloc(
      sizeof(struct sort_infos));
  if (inf == NULL) {
    alloc_error("new_sort_infos");
    return NULL;
  }
  inf->f = NULL;
  inf->f_out = NULL;
  inf->REMOVE_DUPLICATES = 1;
  inf->REVERSE = 1;
  inf->number_of_lines = 0;
  inf->root = new_sort_tree_node();
  inf->resulting_line_number = 0;
  for (int i = 0; i < 0x10000; i++) {
    inf->class_numbers[i] = 0;
    inf->canonical[i] = (unichar) i;
    inf->priority[i] = 0;
  }
  inf->factorize_inflectional_codes = 0;
  return inf;
}
Exemplo n.º 18
0
Cell* read_string(char* in) {
  ReaderState rs;
  Cell stack_root[100];

  rs.state = PST_ATOM;
  rs.cell = 0;
  rs.level = 0;
  rs.stack = (void*)&stack_root;

  int i=0;
  int len = strlen(in);
  for (i=0; i<len; i++) {
    read_char(in[i], &rs);
    if (rs.state>=10) {
      //print("<read error %d at %d.>\n",rs.state,i);
      break;
    }
    //printf("rs %c: %d\n", in[i], rs.state);
  }
  if (rs.level!=0) {
    //print("<missing %d closing parens.>\n",rs.level);
  }
  if (rs.state!=PST_ATOM) {
    //printf("<read error: unexpected end of input.>\n");
  }

  Cell* root = *rs.stack;
  
  if (root) {
    Cell* ret = car(root);
    //if (root->next) free(root->next);
    //free(root);
    return ret;
  }
  return alloc_error(ERR_SYNTAX);
}
Exemplo n.º 19
0
int tei2txt(char *fin, char *fout, const VersatileEncodingConfig* vec) {
    void* html_ctx = init_HTML_character_context();
    if (html_ctx == NULL) {
    alloc_error("tei2txt");
    return ALLOC_ERROR_CODE;
  }

    U_FILE* input = u_fopen(vec, fin, U_READ);
    if (input == NULL) {
    error("Input file '%s' not found!\n", fin);
    free_HTML_character_context(html_ctx);
    return DEFAULT_ERROR_CODE;
  }

    U_FILE* output = u_fopen(vec, fout, U_WRITE);
    if (output == NULL) {
    error("Cannot open output file '%s'!\n", fout);
    u_fclose(input);
    free_HTML_character_context(html_ctx);
    return DEFAULT_ERROR_CODE;
    }

    unichar buffer[5000];

    int i, j, k;
    unichar c;
    if((i = u_fgetc(input)) != EOF) {
        c = (unichar)i;

        for (;;) {
            while(c != '<' && (i = u_fgetc(input)) != EOF) {
                c = (unichar)i;
      }

            j = 0;
            while((i = u_fgetc(input)) != EOF && (c = (unichar)i) != ' '
               && (c = (unichar)i) != '\t' && (c = (unichar)i) != '\n'
               && (c = (unichar)i) != '>') {
                buffer[j++] = c;
            }
            buffer[j] = '\0';
         if (c!='>') {
            /* We do this because we can find <body ...> */
            while((i = u_fgetc(input)) != EOF && (c = (unichar)i) != '>') {}
         }
            //u_printf("Current tag : <%S>\n", buffer);

            if(!u_strcmp(buffer, body)) {
        break;
      } else {
        buffer[0] = '\0';
      }
        }
    } else {
    error("Empty TEI file %s\n", fin);
  }

    char schars[11];

  int first_sentence=1;
    int current_state = 0;
  int inside_sentence=0;
    while ((i = u_fgetc(input)) != EOF) {
        c = (unichar)i;
        switch (current_state) {
            case 0: {
                if(c == '<') {
               current_state = 1;
               inside_sentence=0;
        } else if(c == '&') {
          current_state = 3;
        } else if (inside_sentence) {
          u_fputc(c, output);
        }
                break;
            }
            case 1: {
                if(c == 's' || c == 'S') {
          current_state = 2;
                } else {
                    while((i = u_fgetc(input)) != EOF) {
                        c = (unichar)i;
                        if(c == '>') {
              break;
            }
                    }
                    current_state = 0;
                }
                break;
            }
            case 2: {
                if(c == ' ' || c == '>') {
          current_state = 0;
          inside_sentence=1;
          if (!first_sentence) {
             /* We put a {STOP} tag in order to avoid matches that overlap 2 sentences */
             u_fprintf(output,"\n{STOP}{S}");
          } else {
             first_sentence=0;
          }
                }
                if(c != '>') {
                    while((i = u_fgetc(input)) != EOF) {
                        c = (unichar)i;
                        if(c == '>') {
              break;
            }
                    }
                }
                break;
            }
            case 3: {
                j = 0;
                while(c != ';' && (i = u_fgetc(input)) != EOF) {
                    //u_printf("Current S-character: %C\n", c);
                    schars[j++] = (char)c;
                    c = (unichar)i;
                }
                schars[j] = '\0';
                //u_printf("Current S-chain: %S\n", schars);

                k = get_HTML_character(html_ctx,schars, 1);
                switch (k) {
                    case UNKNOWN_CHARACTER: {
                        u_fputc('?', output);
                        break;
                    }
                    case MALFORMED_HTML_CODE: {
                        error("Malformed HTML character declaration &%s;\n", schars);
                        u_fputc('?', output);
                        break;
                    }
                    default: {
                        c = (unichar)k;
                        u_fputc(c, output);
                        break;
                    }
                }

                schars[0] = '\0';
                current_state = 0;
                break;
            }
        }
    }

    u_fclose(output);
    u_fclose(input);
  free_HTML_character_context(html_ctx);
    u_printf("Done.\n");

  return SUCCESS_RETURN_CODE;
}
Exemplo n.º 20
0
int main_XMLizer(int argc,char* const argv[]) {
if (argc==1) {
   usage();
   return SUCCESS_RETURN_CODE;
}

int output_style=TEI;
char output[FILENAME_MAX]="";
char alphabet[FILENAME_MAX]="";
char normalization[FILENAME_MAX]="";
char segmentation[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
int convLFtoCRLF=1;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_XMLizer,lopts_XMLizer,&index))) {
   switch(val) {
   case 'x': output_style=XML; break;
   case 't': output_style=TEI; break;
   case 'n': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty normalization grammar name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(normalization,options.vars()->optarg);
             break;
   case 'o': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty output file name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(output,options.vars()->optarg);
             break;
   case 'a': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty alphabet file name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(alphabet,options.vars()->optarg);
             break;
   case 's': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty segmentation grammar name\n");
                return USAGE_ERROR_CODE;
             }
             strcpy(segmentation,options.vars()->optarg);
             break;
   case 'V': only_verify_arguments = true;
             break;
   case 'h': usage(); 
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
                         error("Missing argument for option --%s\n",lopts_XMLizer[index].name);
             return USAGE_ERROR_CODE;                         
   case 'k': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_encoding argument\n");
                return USAGE_ERROR_CODE;
             }
             decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
             break;
   case 'q': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_encoding argument\n");
                return USAGE_ERROR_CODE;
             }
             decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
             break;
   case '?': index==-1  ? error("Invalid option -%c\n",options.vars()->optopt) :
                          error("Invalid option --%s\n",options.vars()->optarg);
             return USAGE_ERROR_CODE;             
  
   }
   index=-1;
}

if (options.vars()->optind!=argc-1) {
   error("Invalid arguments: rerun with --help\n");
   return USAGE_ERROR_CODE;
}

if (segmentation[0]=='\0') {
   error("You must specify the segmentation grammar to use\n");
   return USAGE_ERROR_CODE;
}

if (only_verify_arguments) {
  // freeing all allocated memory
  return SUCCESS_RETURN_CODE;
}

char input[FILENAME_MAX];
strcpy(input,argv[options.vars()->optind]);
char snt[FILENAME_MAX];
remove_extension(input,snt);
strcat(snt,"_tmp.snt");
char tmp[FILENAME_MAX];
remove_extension(input,tmp);
strcat(tmp,".tmp");
normalize(input,snt,&vec,KEEP_CARRIAGE_RETURN,convLFtoCRLF,normalization,NULL,1);
struct fst2txt_parameters* p=new_fst2txt_parameters();
p->vec=vec;
p->input_text_file=strdup(snt);
if (p->input_text_file ==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}

p->output_text_file_is_temp=1;
p->output_text_file=strdup(tmp);
if (p->output_text_file==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}
p->fst_file=strdup(segmentation);
if (p->fst_file==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}
p->alphabet_file=strdup(alphabet);
if (p->alphabet_file==NULL) {
   alloc_error("main_XMLizer");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;
}

p->output_policy=MERGE_OUTPUTS;
p->tokenization_policy=WORD_BY_WORD_TOKENIZATION;
p->space_policy=DONT_START_WITH_SPACE;

main_fst2txt(p);

free_fst2txt_parameters(p);

if (output[0]=='\0') {
  remove_extension(input,output);
	strcat(output,".xml");
}

int return_value = xmlize(&vec,snt,output,output_style);

af_remove(snt);
af_remove(tmp);

return return_value;
}
Exemplo n.º 21
0
int main_SpellCheck(int argc,char* const argv[]) {
if (argc==1) {
    usage();
    return SUCCESS_RETURN_CODE;
}

VersatileEncodingConfig vec=VEC_DEFAULT;
int val,index=-1;
char mode=0;
char snt[FILENAME_MAX]="";
char txt[FILENAME_MAX]="";
char output[FILENAME_MAX]="";
char output_set=0;
char output_op='A';
SpellCheckConfig config;
config.max_errors=1;
config.max_SP_INSERT=1;
config.max_SP_SUPPR=1;
config.max_SP_SWAP=1;
config.max_SP_CHANGE=1;
for (int i=0;i<N_SPSubOp;i++) {
    config.score[i]=default_scores[i];
}
config.min_length1=4;
config.min_length2=6;
config.min_length3=12;
config.input_op='D';
config.keyboard=NULL;
config.allow_uppercase_initial=0;
char foo;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_SpellCheck,lopts_SpellCheck,&index))) {
   switch(val) {
   case 's': {
       strcpy(snt,options.vars()->optarg);
       mode='s';
       break;
   }
   case 'f': {
       strcpy(txt,options.vars()->optarg);
       mode='f';
       break;
   }
   case 'o': {
       if (options.vars()->optarg!=NULL) {
           strcpy(output,options.vars()->optarg);
       }
       output_set=1;
       break;
   }
   case 'I': {
       if (!strcmp(options.vars()->optarg,"D") || !strcmp(options.vars()->optarg,"M") || !strcmp(options.vars()->optarg,"U")) {
           config.input_op=options.vars()->optarg[0];
       } else {
       error("Invalid argument %s for option --input-op: should in [DMU]\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 'O': {
       if (!strcmp(options.vars()->optarg,"O") || !strcmp(options.vars()->optarg,"A")) {
           output_op=options.vars()->optarg[0];
       } else {
           error("Invalid argument %s for option --output-op: should in [OA]\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 1: {
       config.keyboard=get_Keyboard(options.vars()->optarg);
       if (config.keyboard==NULL) {
           error("Invalid argument %s for option --keyboard:\nUse --show-keyboards to see possible values\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 2: {
       print_available_keyboards(U_STDOUT);
       return SUCCESS_RETURN_CODE;
   }
   case 10: {
       if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_errors,&foo)) {
           error("Invalid argument %s for --max-errors: should be an integer >=0\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 11: {
       if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_SP_INSERT,&foo)) {
           error("Invalid argument %s for --max-insert: should be an integer >=0\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 12: {
       if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_SP_SUPPR,&foo)) {
           error("Invalid argument %s for --max-suppr: should be an integer >=0\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 13: {
       if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_SP_CHANGE,&foo)) {
           error("Invalid argument %s for --max-change: should be an integer >=0\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 14: {
       if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_SP_SWAP,&foo)) {
           error("Invalid argument %s for --max-swap: should be an integer >=0\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 20: {
       int* scores=config.score;
       if (N_SPSubOp!=sscanf(options.vars()->optarg,"%d,%d,%d,%d,%d,%d,%d,%d,%d%c",
            scores,scores+1,scores+2,scores+3,scores+4,scores+5,
            scores+6,scores+7,scores+8,&foo)) {
            error("Invalid argument %s for option --scores. See --help-scores\n",options.vars()->optarg);
        return USAGE_ERROR_CODE;
       }
       break;
   }
   case 21: {
       usage_scores();
       return SUCCESS_RETURN_CODE;
   }
   case 22: {
       if (3!=sscanf(options.vars()->optarg,"%u,%u,%u%c",
            &config.min_length1,&config.min_length2,&config.min_length3,&foo)) {
            error("Invalid argument %s for option --min-lengths\n",options.vars()->optarg);
        return USAGE_ERROR_CODE;
       }
       break;
   }
   case 23: {
       if (!strcmp(options.vars()->optarg,"yes")) {
           config.allow_uppercase_initial=1;
       } else if (!strcmp(options.vars()->optarg,"no")) {
           config.allow_uppercase_initial=0;
       } else {
           error("Invalid argument %s for option --upper-initial\n",options.vars()->optarg);
       return USAGE_ERROR_CODE;
       }
       break;
   }
   case 'k': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_encoding argument\n");
                return USAGE_ERROR_CODE;
             }
             decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
             break;
   case 'q': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_encoding argument\n");
                return USAGE_ERROR_CODE;
             }
             decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
             break;
   case 'V': only_verify_arguments = true;
             break;
   case 'h': usage();
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
                         error("Missing argument for option --%s\n",lopts_SpellCheck[index].name);
             return USAGE_ERROR_CODE;
   case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
                         error("Invalid option --%s\n",options.vars()->optarg);
             return USAGE_ERROR_CODE;
   }
   index=-1;
}

if (options.vars()->optind==argc) {
   error("Invalid arguments: rerun with --help\n");
   return USAGE_ERROR_CODE;
}

if (mode==0) {
  error("You must use either --snt or --file\n");
  return USAGE_ERROR_CODE;
}

if (only_verify_arguments) {
  // freeing all allocated memory
  return SUCCESS_RETURN_CODE;
}

config.n_dics=argc-options.vars()->optind;
config.dics=(Dictionary**)malloc(config.n_dics*sizeof(Dictionary*));
if (config.dics==NULL) {
    alloc_error("main_SpellCheck");
  return ALLOC_ERROR_CODE;
}

for (int i=0;i<config.n_dics;i++) {
    config.dics[i]=new_Dictionary(&vec,argv[i+options.vars()->optind]);
    if (config.dics[i]==NULL) {
        error("Cannot load dictionary %s\n",argv[i+options.vars()->optind]);
    }
}

config.out=U_STDOUT;
config.n_input_lines=0;
config.n_output_lines=0;

if (mode=='s') {
    /* When working with a .snt, we actually want to work on its err file */
    get_snt_path(snt,txt);
    strcat(txt,"err");
    /* the output must be dlf, and we note the number of lines in the existing
     * dlf file, if any */
    get_snt_path(snt,output);
    strcat(output,"dlf.n");
    U_FILE* f=u_fopen(&vec,output,U_READ);
    if (f!=NULL) {
        u_fscanf(f,"%d",&(config.n_output_lines));
        u_fclose(f);
    }
    get_snt_path(snt,output);
    strcat(output,"dlf");
    output_set=1;
    /* and we force the values for -I and -O */
    config.input_op='U';
    output_op='A';
} else {
    /* If mode=='f', we don't have anything to do since we already
     * defined the default output to stdout */
}

if (output_set) {
    if (output_op=='O') {
        config.out=u_fopen(&vec,output,U_WRITE);
    } else {
        config.out=u_fopen(&vec,output,U_APPEND);
    }
    if (config.out==NULL) {
        error("Cannot open output file %s\n",output);
    for (int i=0;i<config.n_dics;i++) {
      free_Dictionary(config.dics[i]);
    }
    free(config.dics);
    return DEFAULT_ERROR_CODE;
    }
}

config.modified_input=NULL;
char modified_input[FILENAME_MAX]="";
if (config.input_op!='D') {
    strcpy(modified_input,txt);
    strcat(modified_input,".tmp");
    config.modified_input=u_fopen(&vec,modified_input,U_WRITE);
    if (config.modified_input==NULL) {
        error("Cannot open tmp file %s\n",modified_input);
    if (config.out!=U_STDOUT) {
      u_fclose(config.out);
    }
    for (int i=0;i<config.n_dics;i++) {
      free_Dictionary(config.dics[i]);
    }
    free(config.dics);
    return DEFAULT_ERROR_CODE;
    }
}

config.in=u_fopen(&vec,txt,U_READ);
if (config.in==NULL) {
    error("Cannot open file %s\n",txt);
  u_fclose(config.modified_input);
  if (config.out!=U_STDOUT) {
    u_fclose(config.out);
  }
  for (int i=0;i<config.n_dics;i++) {
    free_Dictionary(config.dics[i]);
  }
  free(config.dics);
  return DEFAULT_ERROR_CODE;
}

/* We perform spellchecking */
spellcheck(&config);

/* And we clean */

u_fclose(config.in);

if (config.modified_input!=NULL) {
  /* If we used a tmp file because the input file has to be modified,
   * it's now time to actually modify it */
  u_fclose(config.modified_input);
  af_remove(txt);
  af_rename(modified_input,txt);
}

if (config.out!=U_STDOUT) {
  u_fclose(config.out);
}

for (int i=0;i<config.n_dics;i++) {
  free_Dictionary(config.dics[i]);
}
free(config.dics);

/* Finally, we update the dlf.n and err.n files if mode=='s' */
if (mode=='s') {
    get_snt_path(snt,output);
    strcat(output,"err.n");
    U_FILE* f=u_fopen(&vec,output,U_WRITE);
    if (f!=NULL) {
        u_fprintf(f,"%d",config.n_input_lines);
        u_fclose(f);
    }
    if (config.input_op!='D') {
        get_snt_path(snt,output);
        strcat(output,"dlf.n");
        U_FILE* fw=u_fopen(&vec,output,U_WRITE);
        if (fw!=NULL) {
            u_fprintf(fw,"%d",config.n_output_lines);
            u_fclose(fw);
        }
    }
}

return SUCCESS_RETURN_CODE;
}
Exemplo n.º 22
0
int main_Fst2Txt(int argc,char* const argv[]) {
if (argc==1) {
   usage();
   return SUCCESS_RETURN_CODE;
}

struct fst2txt_parameters* p=new_fst2txt_parameters();
char in_offsets[FILENAME_MAX]="";
char out_offsets[FILENAME_MAX]="";
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;

while (EOF!=(val=options.parse_long(argc,argv,optstring_Fst2Txt,lopts_Fst2Txt,&index))) {
   switch(val) {
   case 't': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty text file name\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE;
             }
             p->input_text_file=strdup(options.vars()->optarg);
             if (p->input_text_file==NULL) {
                alloc_error("main_Fst2Txt");
                free_fst2txt_parameters(p);
                return ALLOC_ERROR_CODE;
             }
             break;
   case 'o': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty text output file name\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE;
             }
             p->output_text_file=strdup(options.vars()->optarg);
			 p->output_text_file_is_temp=0;
             if (p->output_text_file==NULL) {
                alloc_error("main_Fst2Txt");
                free_fst2txt_parameters(p);
                return ALLOC_ERROR_CODE;
             }
             break;
   case 'a': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty alphabet file name\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE;                
             }
             p->alphabet_file=strdup(options.vars()->optarg);
             if (p->alphabet_file==NULL) {
               alloc_error("main_Fst2Txt");
               free_fst2txt_parameters(p);
               return ALLOC_ERROR_CODE;               
             }
             break;
   case 'M': p->output_policy=MERGE_OUTPUTS; break;
   case 'R': p->output_policy=REPLACE_OUTPUTS; break;
   case 'c': p->tokenization_policy=CHAR_BY_CHAR_TOKENIZATION; break;
   case 'w': p->tokenization_policy=WORD_BY_WORD_TOKENIZATION; break;
   case 's': p->space_policy=START_WITH_SPACE; break;
   case 'x': p->space_policy=DONT_START_WITH_SPACE; break;
   case 'V': only_verify_arguments = true;
             break;
   case 'h': usage();
             free_fst2txt_parameters(p);
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
                         error("Missing argument for option --%s\n",lopts_Fst2Txt[index].name);
             free_fst2txt_parameters(p);
             return USAGE_ERROR_CODE; 
   case 'k': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_encoding argument\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE;                 
             }
             decode_reading_encoding_parameter(&(p->vec.mask_encoding_compatibility_input),options.vars()->optarg);
             break;
   case 'q': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_encoding argument\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE; 
             }
             decode_writing_encoding_parameter(&(p->vec.encoding_output),&(p->vec.bom_output),options.vars()->optarg);
             break;
   case '$': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_offsets argument\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE; 
             }
             strcpy(in_offsets,options.vars()->optarg);
             break;
   case '@': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_offsets argument\n");
                free_fst2txt_parameters(p);
                return USAGE_ERROR_CODE; 
             }
             strcpy(out_offsets,options.vars()->optarg);
             break;
   case 'l': p->convLFtoCRLF=0; break;
   case 'r': p->keepCR = 1; break;
   case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
                         error("Invalid option --%s\n",options.vars()->optarg);
             free_fst2txt_parameters(p);
             return USAGE_ERROR_CODE;
   }
   index=-1;
}

if (options.vars()->optind!=argc-1) {
   error("Invalid arguments: rerun with --help\n");
   free_fst2txt_parameters(p);
   return USAGE_ERROR_CODE;
}

if (p->input_text_file==NULL) {
   error("You must specify the text file\n");
   free_fst2txt_parameters(p);
   return USAGE_ERROR_CODE;   
}

if (only_verify_arguments) {
  // freeing all allocated memory
  free_fst2txt_parameters(p);
  return SUCCESS_RETURN_CODE;
}

if (out_offsets[0]!='\0') {
	/* We deal with offsets only if the program is expected to produce some */
	if (in_offsets[0]!='\0') {
		p->v_in_offsets=load_offsets(&(p->vec),in_offsets);
		if (p->v_in_offsets==NULL) {
			error("Cannot load offset file %s\n",in_offsets);
      free_fst2txt_parameters(p);
      return DEFAULT_ERROR_CODE;      
		}
	} else {
		/* If there is no input offset file, we create an empty offset vector
		 * in order to avoid testing whether the vector is NULL or not */
		p->v_in_offsets=new_vector_offset(1);
	}
	p->f_out_offsets=u_fopen(&(p->vec),out_offsets,U_WRITE);
	if (p->f_out_offsets==NULL) {
		error("Cannot create file %s\n",out_offsets);
    free_fst2txt_parameters(p);
    return DEFAULT_ERROR_CODE;     
	}
}

if (p->output_text_file == NULL) {
	char tmp[FILENAME_MAX];
	remove_extension(p->input_text_file, tmp);
	strcat(tmp, ".tmp");
	p->output_text_file_is_temp=1;
	p->output_text_file = strdup(tmp);
	if (p->output_text_file == NULL) {
		alloc_error("main_Fst2Txt");
		free_fst2txt_parameters(p);
		return ALLOC_ERROR_CODE;
	}
}
p->fst_file=strdup(argv[options.vars()->optind]);
if (p->fst_file==NULL) {
   alloc_error("main_Fst2Txt");
   free_fst2txt_parameters(p);
   return ALLOC_ERROR_CODE;   
}

int result=main_fst2txt(p);

free_fst2txt_parameters(p);
return result;
}
Exemplo n.º 23
0
void* sage_mpir_realloc(void *ptr, size_t old_size, size_t new_size)
{
    void* p = sage_realloc(ptr, new_size);
    if (unlikely(!p)) alloc_error(new_size);
    return p;
}
Exemplo n.º 24
0
/* mpir memory functions */
void* sage_mpir_malloc(size_t size)
{
    void* p = sage_malloc(size);
    if (unlikely(!p)) alloc_error(size);
    return p;
}
Exemplo n.º 25
0
/**
 * The same than main, but no call to setBufferMode.
 */
int main_Concord(int argc,char* const argv[]) {
if (argc==1) {
   usage();
   return SUCCESS_RETURN_CODE;
}

int val,index=-1;
struct conc_opt* concord_options = new_conc_opt();
char foo;
VersatileEncodingConfig vec=VEC_DEFAULT;
int ret;
char offset_file[FILENAME_MAX]="";
char PRLG[FILENAME_MAX]="";
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_Concord,lopts_Concord,&index))) {
   switch(val) {
   case 'f': if (options.vars()->optarg[0]=='\0') {
                error("Empty font name argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             concord_options->fontname=strdup(options.vars()->optarg);
             if (concord_options->fontname==NULL) {
                alloc_error("main_Concord");
                free_conc_opt(concord_options);
                return ALLOC_ERROR_CODE;
             }
             break;
   case 's': if (1!=sscanf(options.vars()->optarg,"%d%c",&(concord_options->fontsize),&foo)) {
                /* foo is used to check that the font size is not like "45gjh" */
                error("Invalid font size argument: %s\n",options.vars()->optarg);
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             break;
   case 'l': ret=sscanf(options.vars()->optarg,"%d%c%c",&(concord_options->left_context),&foo,&foo);
             if (ret==0 || ret==3 || (ret==2 && foo!='s') || concord_options->left_context<0) {
                error("Invalid left context argument: %s\n",options.vars()->optarg);
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;                
             }
             if (ret==2) {
                concord_options->left_context_until_eos=1;
             }
             break;
   case 'r': ret=sscanf(options.vars()->optarg,"%d%c%c",&(concord_options->right_context),&foo,&foo);
             if (ret==0 || ret==3 || (ret==2 && foo!='s') || concord_options->right_context<0) {
                error("Invalid right context argument: %s\n",options.vars()->optarg);
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;                
             }
             if (ret==2) {
                concord_options->right_context_until_eos=1;
             }
             break;
   case 'L': concord_options->convLFtoCRLF=0; break;
   case 0: concord_options->sort_mode=TEXT_ORDER; break;
   case 1: concord_options->sort_mode=LEFT_CENTER; break;
   case 2: concord_options->sort_mode=LEFT_RIGHT; break;
   case 3: concord_options->sort_mode=CENTER_LEFT; break;
   case 4: concord_options->sort_mode=CENTER_RIGHT; break;
   case 5: concord_options->sort_mode=RIGHT_LEFT; break;
   case 6: concord_options->sort_mode=RIGHT_CENTER; break;
   case 7: concord_options->result_mode=DIFF_; break;
   case 8: concord_options->only_ambiguous=1; break;
   case 9: {
     strcpy(PRLG,options.vars()->optarg);
     char* pos=strchr(PRLG,',');
     if (pos==NULL || pos==PRLG || *(pos+1)=='\0') {
       error("Invalid argument for option --PRLG: %s\n",options.vars()->optarg);
       free_conc_opt(concord_options);
       return USAGE_ERROR_CODE;
     }
     *pos='\0';
     strcpy(offset_file,pos+1);
     break;
   }
   case 10: concord_options->only_matches=1; break;
   case 11: concord_options->result_mode=LEMMATIZE_; break;
   case 12: concord_options->result_mode=CSV_; break;
   case 'H': concord_options->result_mode=HTML_; break;
   case 't': {
     concord_options->result_mode=TEXT_;
     if (options.vars()->optarg!=NULL) {
       strcpy(concord_options->output,options.vars()->optarg);
     }
     break;
   }
   case 'g': concord_options->result_mode=GLOSSANET_;
             if (options.vars()->optarg[0]=='\0') {
                error("Empty glossanet script argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;                   
             }
             concord_options->script=strdup(options.vars()->optarg);
             if (concord_options->script==NULL) {
                alloc_error("main_Concord");
                free_conc_opt(concord_options);
                return ALLOC_ERROR_CODE;                   
             }
             break;
   case 'p': concord_options->result_mode=SCRIPT_;
             if (options.vars()->optarg[0]=='\0') {
                error("Empty script argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;                
             }
             concord_options->script=strdup(options.vars()->optarg);
             if (concord_options->script==NULL) {
                alloc_error("main_Concord");
                free_conc_opt(concord_options);
                return ALLOC_ERROR_CODE;                 
             }
             break;
   case 'i': concord_options->result_mode=INDEX_; break;
   case 'u': concord_options->result_mode=UIMA_;
             if (options.vars()->optarg!=NULL) {
                strcpy(offset_file,options.vars()->optarg);
             }
             concord_options->original_file_offsets=1;
             break;
   case 'e': concord_options->result_mode=XML_;
             if (options.vars()->optarg!=NULL) {
                strcpy(offset_file, options.vars()->optarg);
                concord_options->original_file_offsets=1;
             }
             break;
   case 'w': concord_options->result_mode=XML_WITH_HEADER_; 
             if (options.vars()->optarg!=NULL) {
                strcpy(offset_file, options.vars()->optarg);
                concord_options->original_file_offsets = 1;
             }
             break;
   case '$': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_offsets argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             strcpy(concord_options->input_offsets,options.vars()->optarg);
             break;
   case '@': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_offsets argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             strcpy(concord_options->output_offsets,options.vars()->optarg);
             break;
   case 'A': concord_options->result_mode=AXIS_; break;
   case 'x': concord_options->result_mode=XALIGN_; break;
   case 'm': concord_options->result_mode=MERGE_;
             if (options.vars()->optarg[0]=='\0') {
                error("Empty output file name argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             strcpy(concord_options->output,options.vars()->optarg);
             break;
   case 'a': if (options.vars()->optarg[0]=='\0') {
                error("Empty alphabet argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;                
             }
             concord_options->sort_alphabet=strdup(options.vars()->optarg);
             if (concord_options->sort_alphabet==NULL) {
                alloc_error("main_Concord");
                free_conc_opt(concord_options);
                return ALLOC_ERROR_CODE;            }
             break;
   case 'T': concord_options->thai_mode=1; break;
   case 'd': if (options.vars()->optarg[0]=='\0') {
                error("Empty snt directory argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             strcpy(concord_options->working_directory,options.vars()->optarg);
             break;
   case 'V': only_verify_arguments = true;
             break;             
   case 'h': usage();
             free_conc_opt(concord_options); 
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
                         error("Missing argument for option --%s\n",lopts_Concord[index].name);
             free_conc_opt(concord_options);
             return USAGE_ERROR_CODE;
   case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
                         error("Invalid option --%s\n",options.vars()->optarg);
             free_conc_opt(concord_options);
             return USAGE_ERROR_CODE;
   case 'k': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_encoding argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
             break;
   case 'q': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_encoding argument\n");
                free_conc_opt(concord_options);
                return USAGE_ERROR_CODE;
             }
             decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
             break;
   }
   index=-1;
}

if (options.vars()->optind!=argc-1) {
   error("Invalid arguments: rerun with --help\n");
   free_conc_opt(concord_options);
   return USAGE_ERROR_CODE;
}
if (concord_options->fontname==NULL || concord_options->fontsize<=0) {
   if (concord_options->result_mode==HTML_ || concord_options->result_mode==GLOSSANET_) {
      error("The specified output mode is an HTML file: you must specify font parameters\n");
      free_conc_opt(concord_options);
      return USAGE_ERROR_CODE;      
   }
}

if (only_verify_arguments) {
  // freeing all allocated memory
  free_conc_opt(concord_options);
  return SUCCESS_RETURN_CODE;
}

U_FILE* concor=u_fopen(&vec,argv[options.vars()->optind],U_READ);
if (concor==NULL) {
   error("Cannot open concordance index file %s\n",argv[options.vars()->optind]);
   free_conc_opt(concord_options);
   return DEFAULT_ERROR_CODE;   
}

if (concord_options->working_directory[0]=='\0') {
   get_path(argv[options.vars()->optind],concord_options->working_directory);
}
if (concord_options->only_matches) {
  concord_options->left_context=0;
  concord_options->right_context=0;
}
/* We compute the name of the files associated to the text */
struct snt_files* snt_files=new_snt_files_from_path(concord_options->working_directory);
ABSTRACTMAPFILE* text=af_open_mapfile(snt_files->text_cod,MAPFILE_OPTION_READ,0);
if (text==NULL) {
  error("Cannot open file %s\n",snt_files->text_cod);
  free_snt_files(snt_files);
  u_fclose(concor);
  free_conc_opt(concord_options);
  return DEFAULT_ERROR_CODE;
}
struct text_tokens* tok=load_text_tokens(&vec,snt_files->tokens_txt);
if (tok==NULL) {
  error("Cannot load text token file %s\n",snt_files->tokens_txt);
  af_close_mapfile(text);
  free_snt_files(snt_files);
  u_fclose(concor);
  free_conc_opt(concord_options);
  return DEFAULT_ERROR_CODE;
}

U_FILE* f_enter=u_fopen(BINARY,snt_files->enter_pos,U_READ);
int n_enter_char=0;
int* enter_pos=NULL;
/* New lines are encoded in 'enter.pos' files. Those files will disappear in the future */
if (f_enter==NULL) {
  error("Cannot open file %s\n",snt_files->enter_pos);
}
else {
  long size=get_file_size(f_enter);
  enter_pos=(int*)malloc(size);
  if (enter_pos==NULL) {
    alloc_error("main_Concord");
    u_fclose(f_enter);
    free_text_tokens(tok);
    af_close_mapfile(text);
    free_snt_files(snt_files);
    u_fclose(concor);
    free_conc_opt(concord_options);
    return ALLOC_ERROR_CODE;     
  }
  n_enter_char=(int)fread(enter_pos,sizeof(int),size/sizeof(int),f_enter);
  if (n_enter_char!=(int)(size/sizeof(int))) {
    error("Read error on enter.pos file in main_Concord\n");
    u_fclose(f_enter);
    free(enter_pos);
    free_text_tokens(tok);
    af_close_mapfile(text);
    free_snt_files(snt_files);
    u_fclose(concor);
    free_conc_opt(concord_options);
    return DEFAULT_ERROR_CODE;
  }
  u_fclose(f_enter);
}
if (concord_options->result_mode==INDEX_ || concord_options->result_mode==UIMA_ || 
    concord_options->result_mode==XML_ || concord_options->result_mode==XML_WITH_HEADER_ ||
    concord_options->result_mode==AXIS_) {
   /* We force some options for index, uima and axis files */
   concord_options->left_context=0;
   concord_options->right_context=0;
   concord_options->sort_mode=TEXT_ORDER;
}
if (concord_options->only_ambiguous && concord_options->result_mode!=LEMMATIZE_) {
  /* We force text order when displaying only ambiguous outputs */
  concord_options->sort_mode=TEXT_ORDER;
}
if (concord_options->result_mode==HTML_ || concord_options->result_mode==DIFF_ || concord_options->result_mode==LEMMATIZE_) {
  /* We need the offset file if and only if we have to produce
   * an html concordance with positions in .snt file */
  concord_options->snt_offsets=load_snt_offsets(snt_files->snt_offsets_pos);
  if (concord_options->snt_offsets==NULL) {
    error("Cannot read snt offset file %s\n",snt_files->snt_offsets_pos);
    free(enter_pos);    
    free_text_tokens(tok);
    af_close_mapfile(text);
    free_snt_files(snt_files);
    u_fclose(concor);
    free_conc_opt(concord_options);
    return DEFAULT_ERROR_CODE;    
  }
}
if (offset_file[0]!='\0') {
  concord_options->uima_offsets=load_uima_offsets(&vec,offset_file);
  if (concord_options->uima_offsets==NULL) {
    error("Cannot read offset file %s\n",offset_file);
    free(enter_pos); 
    free_text_tokens(tok);
    af_close_mapfile(text);
    free_snt_files(snt_files);
    u_fclose(concor);
    free_conc_opt(concord_options);
    return DEFAULT_ERROR_CODE;    
  }
}
if (PRLG[0]!='\0') {
  concord_options->PRLG_data=load_PRLG_data(&vec,PRLG);
  if (concord_options->PRLG_data==NULL) {
    error("Cannot read PRLG file %s\n",PRLG);
    free(enter_pos);
    free_text_tokens(tok);
    af_close_mapfile(text);
    free_snt_files(snt_files);
    u_fclose(concor);
    free_conc_opt(concord_options);
    return DEFAULT_ERROR_CODE;    
  }
}
if (concord_options->result_mode==CSV_) {
  concord_options->sort_mode=TEXT_ORDER;
  concord_options->only_matches=1;
}

/* Once we have set all parameters, we call the function that
 * will actually create the concordance. */
create_concordance(&vec,concor,text,tok,n_enter_char,enter_pos,concord_options);

free(enter_pos);
free_text_tokens(tok);
af_close_mapfile(text);
free_snt_files(snt_files);
u_fclose(concor);
free_conc_opt(concord_options);

u_printf("Done.\n");

return SUCCESS_RETURN_CODE;
}
Exemplo n.º 26
0
bool WTConnection::parse_url(const char *url)
{
	unsigned int proto_length;
	char *port_str;
	int domain_length;

	// Get the protocol
	protocol = static_cast<char *>(calloc(5, sizeof(char)));
	if(protocol == NULL)
		alloc_error("protocol", 5);
	proto_length = strcspn(url, "://");
	if(proto_length == strlen(url))
	{
		// No protocol, assume HTTP
		strncpy(this->protocol, "http\0", 5);
	}
	 else
	{
		this->protocol = static_cast<char *>(
				 realloc(this->protocol,
					 sizeof(char) * (proto_length + 1)));
		strncpy(this->protocol, url, proto_length);
		this->protocol[proto_length] = '\0';
		url += (proto_length + 3);  // skip proto and ://
	};

	for(unsigned int nextchar = 0; nextchar < proto_length; nextchar++)
		this->protocol[nextchar] = (char)tolower(this->protocol[nextchar]);

	if(strcmp("https", this->protocol) == 0) {
		port = 443;
	} else if(strcmp("http", this->protocol) == 0) {
		port = 80;
	} else if(strcmp("ftp", this->protocol) == 0) {
		port = 21;
	} else if(strcmp("gopher", this->protocol) == 0) {
		port = 70;
	} else {
		fprintf(stderr, "unrecognised protocol %s\n", protocol);
		last_error = "unrecognised protocol";
		free(this->protocol);
		return false;
	};

	domain_length = strcspn(url, "/");
	this->domain = static_cast<char *>(calloc(domain_length + 1, sizeof(char)));
	if(this->domain == NULL)
		alloc_error("domain", domain_length);
	strncpy(domain, url, domain_length);
	this->domain[domain_length] = '\0';
	if(domain[0] == '[')
	{
		//IPv6 address.
		port_str = strrchr(this->domain, (int)':');
		//ensure this isn't the last oct of a v6 address
		if(strchr(port_str, (int)']') == NULL)
		{
			int temp_port;
			temp_port = static_cast<int>(strtol(static_cast<char *>(port_str + 1), NULL, 10));
			if(temp_port > 65535)
			{
				fprintf(stderr, "warning: port %d > 65535; "
					"defaulting to %d\n", temp_port, port);
			}
			 else
			{
				port = temp_port;
			};
			port_str[0] = '\0';
		};
	}
	 else
	{
		port_str = strchr(this->domain, static_cast<int>(':'));
		if(port_str != NULL)
		{
			int temp_port;
			temp_port = atoi(static_cast<char *>((port_str + 1)));
			if(temp_port > 65535)
			{
				fprintf(stderr, "warning: port %d > 65535; "
					"defaulting to %d\n", temp_port, port);
			}
			 else
			{
				port = temp_port;
			};
			port_str[0] = '\0';
		};
	};

	if(static_cast<unsigned int>(domain_length) == strlen(url))
	{
		this->uri = static_cast<char *>(calloc(2, sizeof(char)));
		if(this->uri == NULL)
			alloc_error("uri", 2);
		this->uri[0] = '/'; this->uri[1] = '\0';
	}
	 else
	{
		size_t length = strlen(url) - domain_length;
		this->uri = static_cast<char *>(calloc(length + 1, sizeof(char)));
		if(this->uri == NULL)
			alloc_error("uri", length);
		strncpy(uri, (url + domain_length), length);
		this->uri[length] = '\0';
		this->query_string = strchr(uri, static_cast<int>('?'));
	};
	
	return true;
}
Exemplo n.º 27
0
int main_PersistResource(int argc,char* const argv[]) {
if (argc==1) {
   usage();
   return SUCCESS_RETURN_CODE;
}

const char *resource_file = NULL;
int res_graph=0;
int res_alphabet=0;
int res_dico=0;
int unpersist=0;
int verbose=0;
VersatileEncodingConfig vec = VEC_DEFAULT;
int val,index=-1;
bool only_verify_arguments = false;
const char*output_file = NULL;
const char*resource_type = NULL;
UnitexGetOpt options;

while (EOF!=(val=options.parse_long(argc,argv,optstring_PersistResource,lopts_PersistResource,&index))) {
   switch(val) {
   case 'a': res_alphabet = 1; resource_type = "alphabet"; break;
   case 'g': res_graph = 1; resource_type = "graph"; break;
   case 'd': res_dico = 1; resource_type = "dictionary"; break;
   case 'u': unpersist = 1; break;
   case 'v': verbose = 1; break;
   case 'o': if (options.vars()->optarg[0]=='\0') {
                error("Empty output argument\n");
                return USAGE_ERROR_CODE;
             }
             output_file = options.vars()->optarg; // FIXME(gvollant)
             break;
   case 'V': only_verify_arguments = true;
             break;   
   case 'h': usage(); 
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt):
                         error("Missing argument for option --%s\n",lopts_PersistResource[index].name);
             return USAGE_ERROR_CODE;
   case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
                         error("Invalid option --%s\n",options.vars()->optarg);
             return USAGE_ERROR_CODE;
   case 'k':
   case 'q': /* ignore -k and -q parameter instead to raise an error */
             break;
   }
   index=-1;
}

if ((res_graph+res_alphabet+res_dico) != 1) {
	error("Invalid arguments: rerun with --help\n");
	return USAGE_ERROR_CODE;
}

if ((output_file!=NULL) && (unpersist!=0)) {
	error("Invalid arguments: rerun with --help\n");
	return USAGE_ERROR_CODE;
}

if (options.vars()->optind!=argc-1) {
	error("Invalid arguments: rerun with --help\n");
	return USAGE_ERROR_CODE;
}

if (only_verify_arguments) {
	// freeing all allocated memory
	return SUCCESS_RETURN_CODE;
}

resource_file = argv[options.vars()->optind];
size_t size_buf_persisted_filename = strlen(resource_file) + 0x200;
char* buf_persisted_filename = (char*)malloc(size_buf_persisted_filename +1);
if (buf_persisted_filename == NULL) {
	alloc_error("PersistResource's main");
	return ALLOC_ERROR_CODE;
}
*buf_persisted_filename='\0';
if (unpersist == 0) {
	int result = 0;
	if (res_alphabet)
		result = standard_load_persistence_alphabet(resource_file, buf_persisted_filename, size_buf_persisted_filename);
	if (res_graph)
		result = standard_load_persistence_fst2(resource_file, buf_persisted_filename, size_buf_persisted_filename);
	if (res_dico)
		result = standard_load_persistence_dictionary(resource_file, buf_persisted_filename, size_buf_persisted_filename);
	if (result && verbose)
		u_printf("Success on persist %s resource %s to persisted name %s\n", resource_type, resource_file, buf_persisted_filename);
	if (!result)
		error("The %s resource %s cannnot be persisted\n", resource_type, resource_file);


	if (result && (output_file != NULL)) {
		U_FILE* text = u_fopen(&vec, output_file, U_WRITE);
		if (text == NULL) {
			error("Cannot create text file %s\n", output_file);
			free(buf_persisted_filename);
			return DEFAULT_ERROR_CODE;
		}
		u_fprintf(text, "%s", buf_persisted_filename);
		u_fclose(text);
	}

	free(buf_persisted_filename);
	return result ? SUCCESS_RETURN_CODE : DEFAULT_ERROR_CODE;
}
else
{
	if (res_alphabet)
		standard_unload_persistence_alphabet(resource_file);
	if (res_graph)
		standard_unload_persistence_fst2(resource_file);
	if (res_dico)
		standard_unload_persistence_dictionary(resource_file);
	u_printf("The %s resource %s unpersisted\n", resource_type, resource_file);
	return SUCCESS_RETURN_CODE;
}

}
Exemplo n.º 28
0
int main_MultiFlex(int argc,char* const argv[]) {
if (argc==1) {
   usage();
   return SUCCESS_RETURN_CODE;
}

char output[FILENAME_MAX]="";
char config_dir[FILENAME_MAX]="";
char alphabet[FILENAME_MAX]="";
char pkgdir[FILENAME_MAX]="";
char* named=NULL;
int is_korean=0;
// default policy is to compile only out of date graphs
GraphRecompilationPolicy graph_recompilation_policy = ONLY_OUT_OF_DATE;
//Current language's alphabet
int error_check_status=SIMPLE_AND_COMPOUND_WORDS;
VersatileEncodingConfig vec=VEC_DEFAULT;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_MultiFlex,lopts_MultiFlex,&index))) {
   switch(val) {
   case 'o': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty DELAF file name\n");
                free(named);
                return USAGE_ERROR_CODE;
             }
             strcpy(output,options.vars()->optarg);
             break;
   case 'a': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty alphabet file name\n");
                free(named);
                return USAGE_ERROR_CODE;
             }
             strcpy(alphabet,options.vars()->optarg);
             break;
   case 'd': strcpy(config_dir,options.vars()->optarg); break;
   case 'K': is_korean=1;
             break;
   case 's': error_check_status=ONLY_SIMPLE_WORDS; break;
   case 'c': error_check_status=ONLY_COMPOUND_WORDS; break;
   case 'f': graph_recompilation_policy = ALWAYS_RECOMPILE; break;
   case 'n': graph_recompilation_policy = NEVER_RECOMPILE;  break;
   case 't': graph_recompilation_policy = ONLY_OUT_OF_DATE; break;
   case 'k': if (options.vars()->optarg[0]=='\0') {
                error("Empty input_encoding argument\n");
                free(named);
                return USAGE_ERROR_CODE;
             }
             decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
             break;
   case 'q': if (options.vars()->optarg[0]=='\0') {
                error("Empty output_encoding argument\n");
                free(named);
                return USAGE_ERROR_CODE;
             }
             decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
             break;
   case 'p': if (options.vars()->optarg[0]=='\0') {
                error("You must specify a non empty package directory name\n");
                free(named);
                return USAGE_ERROR_CODE;
             }
             strcpy(pkgdir,options.vars()->optarg);
             break;
   case 'r': if (named==NULL) {
                  named=strdup(options.vars()->optarg);
                  if (named==NULL) {
                     alloc_error("main_Grf2Fst2");
                     return ALLOC_ERROR_CODE;
                  }
             } else {
                   char* more_names = (char*)realloc((void*)named,strlen(named)+strlen(options.vars()->optarg)+2);
                 if (more_names) {
                  named = more_names;
                 } else {
                  alloc_error("main_MultiFlex");
                  free(named);
                  return ALLOC_ERROR_CODE;
                 }
                 strcat(named,";");
                 strcat(named,options.vars()->optarg);
             }
             break;
   case 'V': only_verify_arguments = true;
             break;
   case 'h': usage();
             free(named);
             return SUCCESS_RETURN_CODE;
   case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
                         error("Missing argument for option --%s\n",lopts_MultiFlex[index].name);
             free(named);
             return USAGE_ERROR_CODE;
   case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
                         error("Invalid option --%s\n",options.vars()->optarg);
             free(named);
             return USAGE_ERROR_CODE;
   }
   index=-1;
}

if (options.vars()->optind!=argc-1) {
   error("Invalid arguments: rerun with --help\n");
   free(named);
   return USAGE_ERROR_CODE;
}

if (output[0]=='\0') {
   error("You must specify the output DELAF name\n");
   free(named);
   return USAGE_ERROR_CODE;
}

if (only_verify_arguments) {
  // freeing all allocated memory
  free(named);
  return SUCCESS_RETURN_CODE;
}

//Load morphology description
char morphology[FILENAME_MAX];
new_file(config_dir,"Morphology.txt",morphology);
//int config_files_status=CONFIG_FILES_OK;
Alphabet* alph=NULL;
if (alphabet[0]!='\0') {
   //Load alphabet
   alph=load_alphabet(&vec,alphabet,1);  //To be done once at the beginning of the inflection
   if (alph==NULL) {
      error("Cannot open alphabet file %s\n",alphabet);
      free(named);
      return DEFAULT_ERROR_CODE;
   }
}
//Init equivalence files
char equivalences[FILENAME_MAX];
new_file(config_dir,"Equivalences.txt",equivalences);

/* Korean */
Korean* korean=NULL;
if (is_korean) {
   if (alph==NULL) {
      error("Cannot initialize Korean data with a NULL alphabet\n");
      free(named);
      return DEFAULT_ERROR_CODE;
   }
    korean=new Korean(alph);
}
MultiFlex_ctx* p_multiFlex_ctx=new_MultiFlex_ctx(config_dir,
                                                 morphology,
                                                 equivalences,
                                                 &vec,
                                                 korean,
                                                 pkgdir,
                                                 named,
                                                 graph_recompilation_policy);

//DELAC inflection
int return_value = inflect(argv[options.vars()->optind],output,p_multiFlex_ctx,alph,error_check_status);

free(named);

for (int count_free_fst2=0;count_free_fst2<p_multiFlex_ctx->n_fst2;count_free_fst2++) {
    free_abstract_Fst2(p_multiFlex_ctx->fst2[count_free_fst2],&(p_multiFlex_ctx->fst2_free[count_free_fst2]));
    p_multiFlex_ctx->fst2[count_free_fst2] = NULL;
}

free_alphabet(alph);

free_MultiFlex_ctx(p_multiFlex_ctx);

if (korean!=NULL) {
    delete korean;
}

u_printf("Done.\n");
return return_value;
}
Exemplo n.º 29
0
bool WTOAuthConnection::gen_sigbase_and_auth(const char *req_type, const void *data)
{
	char *base_uri; size_t uri_length; char *stripped_uri; size_t stripped_len;
	WTDictionary *param_dict; WTSizedBuffer *params; char *next_param; char *enc_params;
	char nonce[8], *timestamp; size_t timestamp_len;
	char *encoded_uri; size_t sig_base_len;
	char *key; unsigned char *signature; size_t key_len; unsigned int signature_len;
	char *b64_sig;  size_t b64_sig_len = 28; char *enc_b64_sig;
	char *auth_header; size_t auth_header_len;
	
	//
	// Ensure we are needed/wanted
	if(consumer_key == NULL && token == NULL) return false;
	
	
	// 
	// Calculate the length of the URI string
	stripped_uri = strchr(uri, static_cast<int>('?'));
	if(stripped_uri != NULL)
	{
		stripped_len = abs(uri - stripped_uri);
		stripped_uri = static_cast<char *>(calloc(stripped_len + 1, sizeof(char)));
		strncpy(stripped_uri, uri, stripped_len);
		stripped_uri[stripped_len] = '\0';
	} else {
		stripped_uri = strdup(uri);
		stripped_len = strlen(uri);
	}
	
	uri_length  = strlen(protocol) + 3 + strlen(domain); // 3 is for "://"
	uri_length += stripped_len;	// add the URI
	uri_length++;			// add NUL byte
	
	
	
	// 
	// Create the Base String URI
	base_uri = static_cast<char *>(calloc(uri_length, sizeof(char)));
	if(base_uri == NULL) alloc_error("OAuth base string URI buffer", uri_length);
	snprintf(base_uri, uri_length, "%s://%s%s", protocol, domain, stripped_uri);
	
	
	
	// 
	// Generate nonce and timestamp
	timestamp_len = snprintf(NULL, 0, "%ld", time(NULL)) + 1;
	timestamp = static_cast<char *>(calloc(timestamp_len, sizeof(char)));
	if(timestamp == NULL) alloc_error("OAuth timestamp buffer", timestamp_len);
	snprintf(timestamp, timestamp_len, "%ld", time(NULL));
	
	srand(time(NULL));
	snprintf(nonce, sizeof(nonce), "%02x%02x%02x%02x",
		 rand() % 128, rand() % 128, rand() % 128, rand() % 128);
	
	
	
	// 
	// Parameters
	param_dict = new WTDictionary;
	
	next_param = (this->query_string == NULL ? NULL : this->query_string+1);
	
	while (next_param != NULL)
	{
		char *name, *value;
		
		value = strchr(next_param, static_cast<int>('='));
		if(value != NULL)
		{
			value[0] = '\0';	// Replace = with \0 for name
			value++;
		}
		
		name = next_param;
		
		next_param = strchr(value, static_cast<int>('&'));
		if(next_param != NULL)
		{
			next_param[0] = '\0';	// Terminate the value (or name)
			next_param++;
		}
		
		param_dict->set(name, (value == NULL ? strdup("") : strdup(value)));
		if(value != NULL) value[-1] = '=';
		if(next_param != NULL) next_param[-1] = '&';
	}
	
	if(consumer_key != NULL)
		param_dict->set("oauth_consumer_key", strdup(consumer_key));
	if(token != NULL)
		param_dict->set("oauth_token", strdup(token));
	
	param_dict->set("oauth_nonce", strdup(nonce));
	param_dict->set("oauth_signature_method", strdup(sigmeth_enum_to_str(sig_method)));
	param_dict->set("oauth_timestamp", strdup(timestamp));
	param_dict->set("oauth_version", strdup("1.0"));
	
	params = param_dict->all("%s=%s&");
	
	
	
	// 
	// Signature Base String generation
	params->buffer[params->buffer_len - 2] = '\0';	// remove trailing &
	encoded_uri = URLEncode(base_uri);
	enc_params = URLEncode(params->buffer);
	free(params->buffer);
	free(params);
	params = NULL;
	sig_base_len = snprintf(NULL, 0, "%s&%s&%s",
				req_type, encoded_uri, enc_params);
	sig_base_len++;
	sig_base = static_cast<char *>(calloc(sig_base_len, sizeof(char)));
	if(sig_base == NULL) alloc_error("OAuth signature base string buffer", sig_base_len);
	snprintf(sig_base, sig_base_len, "%s&%s&%s",
		 req_type, encoded_uri, enc_params);
	//fprintf(stderr, "OAUTH DEBUG: Signature base string is %s\n", sig_base);
	//fflush(stderr);
	
	
	// 
	// Generate the real signature now.
	key_len = snprintf(NULL, 0, "%s&%s", (consumer_secret == NULL ? "" : consumer_secret), (token_secret == NULL ? "" : token_secret));
	key_len++;
	key = static_cast<char *>(calloc(key_len, sizeof(char)));
	if(key == NULL) alloc_error("OAuth private key", key_len);
	snprintf(key, key_len, "%s&%s", (consumer_secret == NULL ? "" : consumer_secret), (token_secret == NULL ? "" : token_secret));
	signature = static_cast<unsigned char *>(calloc(EVP_MAX_MD_SIZE, sizeof(char)));
	if(signature == NULL) alloc_error("OAuth HMAC signature buffer", EVP_MAX_MD_SIZE);
	HMAC(EVP_sha1(), static_cast<const void *>(const_cast<const char *>(key)), key_len - 1, reinterpret_cast<const unsigned char *>(const_cast<const char *>(sig_base)), sig_base_len - 1, signature, &signature_len);
	
	
	
	// 
	// base64-encode it!  I love OAuth!
	// You think this is bad?  Wait til you see the auth header code below.
	b64_sig = static_cast<char *>(calloc(b64_sig_len, sizeof(char)));
	if(b64_sig == NULL) alloc_error("base64 buffer", b64_sig_len);
	base64::encoder b64encoder;
	b64_sig_len = b64encoder.encode(reinterpret_cast<const char *>(signature), signature_len, b64_sig);
	b64encoder.encode_end(b64_sig + b64_sig_len);
	
	
	
	// 
	// Authorization[sic.] header
	enc_b64_sig = URLEncode(b64_sig);
	free(b64_sig);
	auth_header_len = snprintf(NULL, 0, "OAuth Realm=\"\",%s%s%s oauth_nonce=\"%s\", oauth_signature_method=\"%s\", oauth_timestamp=\"%s\",%s%s%s oauth_version=\"1.0\", oauth_signature=\"%s\"",
				   (consumer_key == NULL ? "" : " oauth_consumer_key=\""), (consumer_key == NULL ? "" : consumer_key), (consumer_key == NULL ? "" : "\","),
				   nonce, sigmeth_enum_to_str(sig_method), timestamp,
				   (token == NULL ? "" : " oauth_token=\""), (token == NULL ? "" : token), (token == NULL ? "" : "\","),
				   enc_b64_sig);
	auth_header_len++;
	auth_header = static_cast<char *>(calloc(auth_header_len, sizeof(char)));
	if(auth_header == NULL) alloc_error("HTTP Authorization buffer", auth_header_len);
	snprintf(auth_header, auth_header_len, "OAuth Realm=\"\",%s%s%s oauth_nonce=\"%s\", oauth_signature_method=\"%s\", oauth_timestamp=\"%s\",%s%s%s oauth_version=\"1.0\", oauth_signature=\"%s\"",
		 (consumer_key == NULL ? "" : " oauth_consumer_key=\""), (consumer_key == NULL ? "" : consumer_key), (consumer_key == NULL ? "" : "\","),
		 nonce, sigmeth_enum_to_str(sig_method), timestamp,
		 (token == NULL ? "" : " oauth_token=\""), (token == NULL ? "" : token), (token == NULL ? "" : "\","),
		 enc_b64_sig);
	
	http_header("Authorization", strdup(auth_header));
	
	free(auth_header);
	free(signature);
	free(key);
	free(sig_base);
	free(timestamp);
	free(base_uri);
	free(enc_params);
	free(encoded_uri);
	free(enc_b64_sig);
	free(stripped_uri);
	
	delete param_dict;
	
	sig_base = NULL;
	
	return true;
}