Exemple #1
0
const std::string LangMap::getMappedFileNameFromFileName(
        const std::string &fileName) {
    // make sure the lang map file is parsed
    open();

    string mappedFile;

    // try with the file extension
    const string ext = get_file_extension(fileName);
    if (ext != "") {
        mappedFile = getFileName(ext);
        if (mappedFile != "")
            return mappedFile;
        else {
            mappedFile = getFileName(Utils::tolower(ext));
            if (mappedFile != "")
                return mappedFile;
        }
    }

    string fileNameNoPath = strip_file_path(fileName);

    // try with the file name
    mappedFile = getFileName(fileNameNoPath);
    if (mappedFile != "")
        return mappedFile;

    // try with the lower case file name (as our last chance)
    return getFileName(Utils::tolower(fileNameNoPath));
}
Exemple #2
0
/*  ---------------------------------------------------------------------[<]-
    Function: init_resources

    Synopsis: stores needed parameters for the service and application
      - bin_name and appl_version will be used for display only. Can be NULL
      - init_fct: a function starting all the SMT agents needed for the service
      - term_fct: a function disposing resources allocated by init_fct

    Returns: 0 is everything is OK, negative error code otherwise
    ---------------------------------------------------------------------[>]-*/
static int 
init_resources(
    const char *binary_name,
    const char *appl_version,
    SMT_AGENTS_INIT_FCT *init_fct, 
    SMT_AGENTS_TERM_FCT *term_fct)
{
    if (!binary_name)
        return 1;

    application_name = mem_strdup (binary_name);
    if (application_name)
        strip_file_path (application_name);
    application_version = mem_strdup (appl_version ? appl_version : "???");
    application_config = service_get_config_filename (application_name);
    smt_agents_init_fct = init_fct;
    smt_agents_term_fct = term_fct;

    if (!application_name || !application_config || !application_version)
      {
        free_resources();
        return 1;
      }

    return 0;
}
Exemple #3
0
int main (int argc, char *argv [])
{
    bin_name = strip_file_path (argv[0]);

    if (argc < 2 || argc > 3)
      {
         display_usage ();
         return -1;
      }

    if (! load_config (argv[1]) )
        return -1;

    if (argc == 3)
      {
        if (!load_body (argv[2]))
          {
            coprintf ("bad body file");
            return -1;
          }
      }

    coprintf (
        "Sending one mail from [%s] to [%s] via [%s]",
        main_sender,
        main_dest,
        main_server
      );

    smt_init ();                   /*  Initialise SMT kernel    */
    /*  Application is latent - initialise it                   */
    if (agent_lookup (SMT_SOCKET) == NULL)
        sock_init ();
    if (agent_lookup (AGENT_NAME) == NULL)
        tstsmtp_init ();

    thread_create (AGENT_NAME, "");

    /*  Application is active - execute it                      */
    smt_exec_full ();              /*  Run until completed      */

    /*  Application is halted - terminate it                    */
    smt_term ();                   /*  Shut-down SMT kernel     */
    sock_term ();

    mem_free (main_server);
    mem_free (main_sender);
    mem_free (main_dest);
    mem_free (main_body);

    printf ("Allocs=%ld frees=%ld\n", mem_allocs (), mem_frees ());
    mem_assert ();

    return (0);
}
Exemple #4
0
/*  ---------------------------------------------------------------------[<]-
    Function: service_main

    Synopsis: This routine performs the service initialization and then calls
              the user defined service_start() routine to perform majority
              of the work.
    ---------------------------------------------------------------------[>]-*/
static char *
service_get_config_filename (const char *binary_name)
{
    char 
        *res = NULL;

    if (!binary_name || strnull(binary_name))
        return NULL;

    /* we allocate 4 extra char to append the ".cfg" extension */
    res = mem_alloc (strlen(binary_name) + 4 + 1);
    if (res)
      {
        strcpy (res, binary_name);
        strip_file_path (res);
        res = fixed_extension (res, res, "cfg");
      }

    return res;
}