diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-11-28 17:16:40 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-11-28 17:17:09 +0100 |
commit | c4224377cae5490122011157c4586144f9b188d5 (patch) | |
tree | 86ee8a2fe7c9218ec48550860dc6756949921eac /desktop/unx | |
parent | ac28e1c7f2d7a06b92af098f9e1c494bcb74d6d5 (diff) |
Clean up
Change-Id: Idc8aa334dd784b7d55f092b0a0e353bb2f9b38d1
Diffstat (limited to 'desktop/unx')
-rw-r--r-- | desktop/unx/source/pagein.c | 127 | ||||
-rw-r--r-- | desktop/unx/source/pagein.h | 2 | ||||
-rw-r--r-- | desktop/unx/source/start.c | 37 |
3 files changed, 30 insertions, 136 deletions
diff --git a/desktop/unx/source/pagein.c b/desktop/unx/source/pagein.c index 6ffa07bd8809..67ca3670d5f4 100644 --- a/desktop/unx/source/pagein.c +++ b/desktop/unx/source/pagein.c @@ -26,128 +26,49 @@ #include <string.h> /* do_pagein */ -static int do_pagein (const char * filename, size_t * size) +static void do_pagein (const char * filename) { int result; file_image image = FILE_IMAGE_INITIALIZER; - if ((result = file_image_open (&image, filename)) != 0) - return (result); + if (file_image_open (&image, filename) != 0) + return; if ((result = file_image_pagein (&image)) != 0) { fprintf (stderr, "file_image_pagein %s: %s\n", filename, strerror(result)); - goto cleanup_and_leave; } - if (size) - { - *size = image.m_size; - } - -cleanup_and_leave: file_image_close (&image); - return (result); } -/* main */ -int pagein_execute (int argc, char **argv) +void pagein_execute(char const * path, char const * file) { - int i, v = 0; - size_t nfiles = 0, nbytes = 0; - - if (argc < 2) + char fullpath[4096]; + char *p = NULL; + FILE * fp = 0; + memset(fullpath, 0, sizeof(fullpath)); + strncpy (fullpath, path, 3000); + if (!(p = strrchr (fullpath, '/'))) + p = fullpath; + else + p++; + strncpy(p, file, 1024); + p[strlen(p)] = '\0'; + if ((fp = fopen (fullpath, "r")) == 0) { - fprintf ( - stderr, - "%s: Usage: pagein [-v[v]] [-L<path>] [@]<filename> ...\n", - argv[0]); - return (1); - } - for (i = 1; i < argc; i++) + fprintf (stderr, "fopen %s: %s\n", fullpath, strerror(errno)); + return; + } + while (fgets (p, 1024, fp) != 0) { - FILE * fp = 0; - size_t k = 0; - - if (argv[i][0] == '-') - { - /* option */ - int j = 1; - switch (argv[i][j]) - { - case 'v': - /* verbosity level */ - for (v += 1, j += 1; argv[i][j]; j++) - v += (argv[i][j] == 'v'); - break; - case 'L': - /* search path */ - if (chdir (&(argv[i][2])) == -1) - fprintf (stderr, "chdir %s: %s\n", &(argv[i][2]), strerror(errno)); - break; - default: - /* ignored */ - break; - } + p[strlen(p) - 1] = '\0'; - /* next argv */ - continue; - } - - if ((argv[i][0] == '@') && ((fp = fopen (argv[i], "r")) == 0)) - { - char fullpath[4096]; - char *path = NULL; - memset(fullpath, 0, sizeof(fullpath)); - strncpy (fullpath, argv[i] + 1, 3000); - if (!(path = strrchr (fullpath, '/'))) - path = fullpath; - else - path++; - - if ((fp = fopen (&(argv[i][1]), "r")) == 0) - { - fprintf (stderr, "fopen %s: %s\n", &(argv[i][1]), strerror(errno)); - continue; - } - while (fgets (path, 1024, fp) != 0) - { - path[strlen(path) - 1] = '\0', k = 0; - - /* paths relative to the location of the pagein file */ - if (do_pagein (fullpath, &k) == 0) - { - /* accumulate total size */ - nbytes += k; - } - - if (v >= 2) - fprintf (stderr, "pagein(\"%s\") = %d bytes\n", path, (int) k); - nfiles += 1; - } - fclose (fp); - } - else - { - if (fp != 0) - fclose (fp); - - if (do_pagein (argv[i], &k) == 0) - { - /* accumulate total size */ - nbytes += k; - } - - if (v >= 2) - fprintf (stderr, "pagein(\"%s\") = %d bytes\n", argv[i], (int) k); - nfiles += 1; - } + /* paths relative to the location of the pagein file */ + do_pagein (fullpath); } - - if (v >= 1) - fprintf (stderr, "Total: %d files (%d bytes)\n", (int) nfiles, (int) nbytes); - return (0); + fclose (fp); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/unx/source/pagein.h b/desktop/unx/source/pagein.h index 929bab81fe05..c31922b3f1a0 100644 --- a/desktop/unx/source/pagein.h +++ b/desktop/unx/source/pagein.h @@ -22,7 +22,7 @@ #include <sal/config.h> -int pagein_execute(int argc, char **argv); +void pagein_execute(char const * path, char const * file); #endif diff --git a/desktop/unx/source/start.c b/desktop/unx/source/start.c index 9e5f7f1e0c81..3732737b955e 100644 --- a/desktop/unx/source/start.c +++ b/desktop/unx/source/start.c @@ -599,42 +599,15 @@ system_checks( void ) #endif } -static char *build_pagein_path (Args *args, const char *pagein_name) -{ - char *path; - rtl_String *app_path; - - app_path = ustr_to_str (args->pAppPath); - path = malloc ( - RTL_CONSTASCII_LENGTH("@") + app_path->length + strlen (pagein_name) + - 1); - strcpy (path, "@"); - strcpy (path + 1, rtl_string_getStr (app_path)); - strcat (path, pagein_name); - - rtl_string_release( app_path ); - - return path; -} - void exec_pagein (Args *args) { - char *argv[3]; - - /* don't use -L - since that does a chdir that breaks relative paths */ - argv[0] = "dummy-pagein"; - argv[1] = build_pagein_path (args, "pagein-common"); + rtl_String * path = ustr_to_str(args->pAppPath); + pagein_execute(rtl_string_getStr(path), "pagein-common"); if (args->pPageinType) { - argv[2] = build_pagein_path (args, args->pPageinType); - } else - argv[2] = NULL; - - pagein_execute (args->pPageinType ? 3 : 2, argv); - - if (argv[2]) - free (argv[2]); - free (argv[1]); + pagein_execute(rtl_string_getStr(path), args->pPageinType); + } + rtl_string_release(path); } #if HAVE_FEATURE_JAVA |