5.2.2. Convenience functions

Some convenience functions are defined as shown in Example 5.2:

Example 5.2. Convenience functions

static void cdToExecutable() {
    char buf[PATH_MAX + 1];
#ifdef MDE_OS_WIN32
    if(GetModuleFileName(GetModuleHandle(NULL), buf, sizeof(buf)) == 0) 
    {
        MDE_GENERAL_ERROR("Can not find location of executing application");
    }
    char * enddir = strrchr(buf, '\\');
#else
    if (readlink("/proc/self/exe", buf, sizeof(buf) - 1) == -1) 
    {
        MDE_GENERAL_ERROR("Can not find location of executing application");
    }
    char * enddir = strrchr(buf, '/');
#endif
    *enddir = 0;
    chdir(buf);
}

static void errorExit(const char * fmt, const char * arg) 
{
    printf(fmt, arg);
#ifdef MDE_OS_WIN32
    // Pause so that we don't lose the message on exit.
    printf("Press RETURN to exit ...");
    getchar();
#endif
    exit(-1);
}

static void printHelp() {
    printf(
            "SYNTAX: lotion [-resolution arg] [-depth arg] [-theme arg] [-applets args] [-input args]\n\n");

    printf("-resolution\n");
    printf("    800x480\n");
    printf("    800x600\n\n");

    printf("-depth\n");
    printf("    bits per pixel\n\n");

    printf("-theme\n");
    printf("    blue\n");
    printf("    robot\n");
    printf("    minimal\n");

    printf("-applets\n");
    printf("    all\n");
    printf("    default (all)\n");
    printf("    lightshow\n");
    printf("    planet\n");
    printf("    buzzword\n");
    printf("    photo\n");
    printf("    presentation\n");
    printf("    slideshow\n");
    printf("    browser\n\n");

    printf("-input\n");
    printf("    mouse\n");
    printf("    touch <filename>\n");
    
}

static void argErrorExit(const char * fmt, const char * printfArg) {
    printHelp();
    errorExit(fmt, printfArg);
}

Copyright © 2010 ARM. All rights reserved.ARM DUI 0527A‑02a
Non-Confidential - Draft - BetaID070710