pax_global_header00006660000000000000000000000064134141630210014505gustar00rootroot0000000000000052 comment=8229b0d99b4b5f29019dedcb8c51f66bcd0c5577 lsmount-0.2.3/000077500000000000000000000000001341416302100132105ustar00rootroot00000000000000lsmount-0.2.3/CHANGELOG.md000066400000000000000000000017501341416302100150240ustar00rootroot00000000000000# Changelog ## [0.2.3] - 2019-01-05 ### Fixed fixes incompatibility with hurd by removing PATH_MAX ### Changed add compile time check for _POSIX_VERSION ### Removed limits.h is no longer needed ## [0.2.2] - 2018-04-07 ### Fixed don't fill up last column with spaces when show_unused=0 remove hard coded grid size ## [0.2.1] - 2018-02-03 ### Fixed some hardening ### Added add conservative default config file these changelog ## [0.2.0] - 2018-01-22 ### Fixed fixing build problems Revised data structures ### Added add new option --skip add new option --set-colors recognition of color capability ### Changed renamed option --no-file -> --dont-use-file changed behavior of --use-color more intuitive long-opts ### Removed removed option --shrink-eighty ## [0.1.1] - 2014-10-23 ### Fixed more compatible Makefile to git rid of build problems ### Changed renamed global configuration file /etc/lsmount.conf => /etc/lsmountrc ## [0.1.0] - 2014-10-14 First release (just for testing purpose) lsmount-0.2.3/LICENSE000066400000000000000000000014041341416302100142140ustar00rootroot00000000000000This license covers all files. Copyright (c) 2013-2019, Andreas Schwarz Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. lsmount-0.2.3/Makefile000066400000000000000000000031621341416302100146520ustar00rootroot00000000000000.PHONY: all clean install uninstall manpage CC = /usr/bin/gcc CFLAGS += -std=gnu99 -lconfig -D_GNU_SOURCE CFLAGS += `pkg-config --cflags libconfig` LDLIBS += `pkg-config --libs libconfig` LDFLAGS = -ltermcap -z now BIN = lsmount OBJ = lsmount.o lsmgrid.o options.o lsmcolors.o helper.o VPATH = src all: CFLAGS += -O2 -Wall -pedantic -fPIE -D_FORTIFY_SOURCE=1 all: $(BIN) debug: CFLAGS += -g -Og -DDEBUG -Werror -Wextra -pedantic -Wcast-qual -Wcast-align -Wformat -Wformat-nonliteral -Wformat-security -Winit-self -Wmissing-include-dirs -Wno-suggest-attribute=noreturn -Wno-write-strings -Wpointer-arith -Wredundant-decls -Wundef -Wpacked -Wunreachable-code -Wno-unused-parameter -Wconversion -Wshadow -Wstrict-prototypes -Wbad-function-cast -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wnested-externs debug: $(BIN) lsmount: lsmount.o lsmgrid.o options.o lsmcolors.o helper.o $(CC) -o $@ $(OBJ) $(LDLIBS) $(LDFLAGS) lsmount.o: lsmount.c lsmount.h ansicodes.h $(CC) $(CFLAGS) -c -o $@ $< lsmgrid.o: lsmgrid.c lsmgrid.h $(CC) $(CFLAGS) -c -o $@ $< lsmcolors.o: lsmcolors.c lsmcolors.h $(CC) $(CFLAGS) -c -o $@ $< options.o: options.c options.h $(CC) $(CFLAGS) -c -o $@ $< helper.o: helper.c helper.h $(CC) $(CFLAGS) -c -o $@ $< clean: rm -f $(BIN) $(OBJ) rm -f doc/lsmount.1.gz install: lsmount manpage cp lsmount /usr/bin/$(BIN) cp share/lsmount.rc.default /etc/lsmountrc cp doc/lsmount.1.gz /usr/share/man/man1/ uninstall: rm -f /usr/bin/$(BIN) rm -f /etc/lsmountrc rm -f /usr/share/man/man1/lsmount.1.gz manpage: doc/lsmount.txt a2x -f manpage doc/lsmount.txt gzip -f doc/lsmount.1 lsmount-0.2.3/README000066400000000000000000000007131341416302100140710ustar00rootroot00000000000000Overview ========== lsmount is a small program for formatting the /proc/mounts output -------------------- Dependencies -------------------- libc libconfig libtinfo -------------------- Building -------------------- Dependencies debhelper (>=9) libc6-dev libconfig-dev (>=1.4.8) libncureses5-dev asciidoc xmlto gzip -------------------- Build command -------------------- make -------------------- Building manpage -------------------- make manpage lsmount-0.2.3/doc/000077500000000000000000000000001341416302100137555ustar00rootroot00000000000000lsmount-0.2.3/doc/lsmount.txt000066400000000000000000000027271341416302100162270ustar00rootroot00000000000000lsmount(1) ========== :doctype: manpage :man source: lsmount :man manual: lsmount manual Name ---- lsmount - a simple formatter for /proc/mounts DESCRIPTION ----------- gives you a much more readable output of /proc/mounts with optional colorizing, alignment and more useful options. OPTIONS ------- *-a*, *--use-alignment* :: use alignment *-c*, *--use-color*[='auto'] :: use colors *-d*, *--debug* :: show debug outputs *-f*, *--file* 'FILE' :: use another input file *-h*, *--help* :: show help and version *-l*, *--resolv-symlinks* :: resolv symlinks *-s*, *--skip*='dev1','dev2',... :: skip all lines where device is part of comma separated list *-u*, *--show-unused* :: show unused columns *-v*, *--print-vertical* :: vertical output *-x*, *--set-colors*='color1',...,'color6' :: set colors of all columns possible colors are black, red, green, yellow, blue, magenta, cyan, white all short options can be inverted by using the upercase letter, the longopts can be inverted by adding dont- in front. CONFIGURATION ------------- configuration files /etc/lsmountrc, ~/.config/lsmount.rc Available Options are debug, skip, use-color, set-colors, show-unused, resolv-symlinks, use-alignment, vertical as described above. Syntax: option = [false|true|"STRING"]; AUTHOR ------ *lsmount* is written by Andreas Schwarz *contact:* contact@lsmount.org SEE ALSO -------- mount(8) RESOURCES --------- Git: WWW: lsmount-0.2.3/share/000077500000000000000000000000001341416302100143125ustar00rootroot00000000000000lsmount-0.2.3/share/lsmount.rc.default000066400000000000000000000004041341416302100177620ustar00rootroot00000000000000use-alignment = true; use-color = "auto"; debug = false; resolve-symlinks = true; shrink-eighty = false; show-unused = false; print-vertical = false; set-colors = "red,green,blue,yellow,white,white"; skip = ""; lsmount-0.2.3/share/lsmount.rc.example000066400000000000000000000005621341416302100177760ustar00rootroot00000000000000use-alignment = true; use-color = true; debug = false; resolve-symlinks = true; shrink-eighty = false; show-unused = false; print-vertical = false; set-colors = "red,green,blue,yellow,white,white"; skip = "sysfs,proc,udev,sunrpc,devpts,tmpfs,cgroup,pstore,systemd-1,mqueue,securityfs,debugfs,configfs,hugetlbfs,fusectl"; lsmount-0.2.3/src/000077500000000000000000000000001341416302100137775ustar00rootroot00000000000000lsmount-0.2.3/src/ansicodes.h000066400000000000000000000047751341416302100161350ustar00rootroot00000000000000#ifndef ANSICODES_H #define ANSICODES_H #define ANSI_ESC_RESET "\x1b[0m" #define ANSI_ESC_BOLD "\x1b[1m" #define ANSI_ESC_FAINT "\x1b[2m" #define ANSI_ESC_ITALIC "\x1b[3m" #define ANSI_ESC_ULINE "\x1b[4m" #define ANSI_ESC_SBLINK "\x1b[5m" #define ANSI_ESC_RBLINK "\x1b[6m" #define ANSI_ESC_IMGNEG "\x1b[7m" #define ANSI_ESC_CONCEAL "\x1b[8m" #define ANSI_ESC_CROSS "\x1b[9m" #define ANSI_ESC_DFTFONT "\x1b[10m" #define ANSI_ESC_1AFONT "\x1b[11m" #define ANSI_ESC_2AFONT "\x1b[12m" #define ANSI_ESC_3AFONT "\x1b[13m" #define ANSI_ESC_4AFONT "\x1b[14m" #define ANSI_ESC_5AFONT "\x1b[15m" #define ANSI_ESC_6AFONT "\x1b[16m" #define ANSI_ESC_7AFONT "\x1b[17m" #define ANSI_ESC_8AFONT "\x1b[18m" #define ANSI_ESC_9AFONT "\x1b[19m" #define ANSI_ESC_FRACT "\x1b[20m" #define ANSI_ESC_BOFFUDB "\x1b[21m" #define ANSI_ESC_NORMC "\x1b[22m" #define ANSI_ESC_NITNFRA "\x1b[23m" #define ANSI_ESC_NUNDERL "\x1b[24m" #define ANSI_ESC_NBLINK "\x1b[25m" #define ANSI_ESC_RESERVED1 "\x1b[26m" #define ANSI_ESC_IMGPOS "\x1b[27m" #define ANSI_ESC_REVEAL "\x1b[28m" #define ANSI_ESC_NCROSSO "\x1b[29m" #define ANSI_ESC_BLACK "\x1b[30m" // fg color #define ANSI_ESC_RED "\x1b[31m" #define ANSI_ESC_GREEN "\x1b[32m" #define ANSI_ESC_YELLOW "\x1b[33m" #define ANSI_ESC_BLUE "\x1b[34m" #define ANSI_ESC_MAGENTA "\x1b[35m" #define ANSI_ESC_CYAN "\x1b[36m" #define ANSI_ESC_WHITE "\x1b[37m" // fg color #define ANSI_ESC_SET256FG "\x1b[38m" #define ANSI_ESC_DFTTXTC "\x1b[39m" #define ANSI_ESC_BLACKBG "\x1b[40m" // bg color #define ANSI_ESC_REDBG "\x1b[41m" #define ANSI_ESC_GREENBG "\x1b[42m" #define ANSI_ESC_YELLOWBG "\x1b[43m" #define ANSI_ESC_BLUEBG "\x1b[44m" #define ANSI_ESC_MAGENTABG "\x1b[45m" #define ANSI_ESC_CYANBG "\x1b[46m" #define ANSI_ESC_WHITEBG "\x1b[47m" // bg color #define ANSI_ESC_SETX256BG "\x1b[48m" #define ANSI_ESC_DFTBGC "\x1b[49m" #define ANSI_ESC_RESERVED2 "\x1b[50m" #define ANSI_ESC_FRAMED "\x1b[51m" #define ANSI_ESC_ENCIRCLED "\x1b[52m" #define ANSI_ESC_OVERLINED "\x1b[53m" #define ANSI_ESC_NFRMNENC "\x1b[54m" #define ANSI_ESC_NOLINED "\x1b[55m" #define ANSI_ESC_RESERVED3 "\x1b[56m" #define ANSI_ESC_RESERVED4 "\x1b[57m" #define ANSI_ESC_RESERVED5 "\x1b[58m" #define ANSI_ESC_RESERVED6 "\x1b[59m" #define ANSI_ESC_IDEULRL "\x1b[60m" #define ANSI_ESC_IDEDBLURL "\x1b[61m" #define ANSI_ESC_IDEOLLL "\x1b[62m" #define ANSI_ESC_IDEDBLLL "\x1b[63m" #define ANSI_ESC_IDESTRESS "\x1b[64m" #endif lsmount-0.2.3/src/helper.c000066400000000000000000000042571341416302100154320ustar00rootroot00000000000000#include "helper.h" #include #include #include #include #include int is_symlink(const char* filename) { struct stat p_statbuf; if(lstat(filename, &p_statbuf)) { // no file => no symlink return 0; }else{ if(S_ISLNK(p_statbuf.st_mode) == 1) { return 1; }else{ return 0; } } } char* read_file_to_buf(const char* file) { size_t filebuf_size = 1024; // initial size // open read only file stream FILE* stream = fopen(file, "r"); if(NULL == stream) { fprintf(stderr, _("fopen on %s failed (%s)\n"), file, strerror(errno)); exit(1); } // create buffer char* filebuf = malloc(sizeof(char)*(long unsigned int)filebuf_size); if(NULL == filebuf) { fprintf(stderr, _("malloc failed\n")); exit(1); } // init filebuf memset(filebuf, '\0', sizeof(char)*(long unsigned int)filebuf_size); int c = '\0'; // init char for fgetc while( (c=fgetc(stream)) != EOF ) { // expand filebuf by filebuf_size if necessary // n^2 growth if( (size_t)filebuf_size == (size_t)strlen(filebuf)+1) { char* new_filebuf = realloc( filebuf, strlen(filebuf)+(size_t)filebuf_size // double size ); if( NULL == new_filebuf ) { // check if realloc was successful free(filebuf); fprintf(stderr, _("realloc failed\n")); exit(1); }else{ filebuf = new_filebuf; filebuf_size = strlen(filebuf)+(size_t)filebuf_size; } } char buf[2]; // buffer for snprintf snprintf(buf, 2, "%c", c); // read c to buf as char with 0-Byte filebuf = strncat(filebuf, buf, 1); // write char to filebuf } // shrink buffer to really needed size char* shrk_filebuf = realloc(filebuf, sizeof(char)*strlen(filebuf)+1); if( NULL == shrk_filebuf ) { // check if realloc was successful free(filebuf); fprintf(stderr, _("realloc failed\n")); exit(1); }else{ filebuf = shrk_filebuf; filebuf_size = strlen(filebuf)+(size_t)filebuf_size; } if(0 != fclose(stream)) { fprintf(stderr, _("fclose error (%s)\n"), strerror(errno)); exit(1); } return filebuf; } size_t get_buf_lines(const char* buf) { size_t i=0; size_t lines=0; while(i<=strlen(buf)) { if(buf[i] == '\n') { ++lines; } ++i; } return lines; } lsmount-0.2.3/src/helper.h000066400000000000000000000004051341416302100154260ustar00rootroot00000000000000#ifndef HELPER_H #define HELPER_H #define _(STRING) gettext(STRING) #include #include #include int is_symlink(const char* filename); char* read_file_to_buf(const char* file); size_t get_buf_lines(const char* buf); #endif lsmount-0.2.3/src/lsmcolors.c000066400000000000000000000016211341416302100161600ustar00rootroot00000000000000#include #include #include #include #include "lsmcolors.h" #include "ansicodes.h" #include "lsmount.h" void initcolors(void) { colors[0] = ANSI_ESC_RED; colors[1] = ANSI_ESC_GREEN; colors[2] = ANSI_ESC_BLUE; colors[3] = ANSI_ESC_YELLOW; colors[4] = ANSI_ESC_WHITE; colors[5] = ANSI_ESC_WHITE; } char* colortoesc(char* cstr) { if(!strcmp(cstr, "black")) { return ANSI_ESC_BLACK; }else if(!strcmp(cstr, "red")) { return ANSI_ESC_RED; }else if(!strcmp(cstr, "green")) { return ANSI_ESC_GREEN; }else if(!strcmp(cstr, "yellow")) { return ANSI_ESC_YELLOW; }else if(!strcmp(cstr, "blue")) { return ANSI_ESC_BLUE; }else if(!strcmp(cstr, "magenta")) { return ANSI_ESC_MAGENTA; }else if(!strcmp(cstr, "cyan")) { return ANSI_ESC_CYAN; }else if(!strcmp(cstr, "white")) { return ANSI_ESC_WHITE; }else{ printf(_("unknown color\n")); exit(1); } } lsmount-0.2.3/src/lsmcolors.h000066400000000000000000000002001341416302100161550ustar00rootroot00000000000000#ifndef LSMCOLORS_H #define LSMCOLORS_H const char* colors[6]; void initcolors(void); char* colortoesc(char* cstr); #endif lsmount-0.2.3/src/lsmgrid.c000066400000000000000000000112021341416302100156000ustar00rootroot00000000000000#include #include #include #include #include "options.h" #include "ansicodes.h" #include "lsmount.h" #include "lsmgrid.h" #include "lsmcolors.h" #include "helper.h" t_grid* grid_create(size_t columns, size_t rows) { tofree = NULL; tofree_c = 0; if(columns > SIZE_MAX / rows) { // not really likely, but... fprintf(stderr,_("columns*rows > SIZE_MAX => overflow\n")); exit(1); } t_grid* grid = (t_grid*) malloc(sizeof(t_grid)); if(NULL == grid) { return NULL; } grid->elem = (t_elem*) malloc(sizeof(t_elem) * columns * rows); if(NULL == grid->elem) { free(grid); return NULL; } grid->columns = columns; grid->rows = rows; for(size_t i = 0; i < columns * rows; ++i) { grid->elem[i].value = "N/A"; } return grid; } void grid_destroy(t_grid* grid) { for(size_t i=0; ielem); free(grid); } void grid_print(t_grid* grid) { size_t rows = grid->rows; size_t cols = grid->columns; if(use_alignment == 1) { grid_analyse(grid); } if(debug == 1) { printf("cl: "); for(uint8_t i=0; i<6; ++i) { printf("[%lu]", column_length[i]); } putchar('\n'); } for(size_t r=0; r3) { printf("\n"); break; } if(use_color == 1) { printf("%s", colors[c]); } printf("%s ", grid->elem[r*cols+c].value); if( (use_alignment == 1 && show_unused == 1) || (use_alignment == 1 && (show_unused == 0 && c<3)) ) { size_t delta = column_length[c] - strlen(grid->elem[r*cols+c].value); if(delta>0) { for(size_t d=0; drows; size_t cols = grid->columns; for(size_t r=0; relem[r*cols+c].value)>column_length[c]) { column_length[c] = strlen(grid->elem[r*cols+c].value); } } } } int grid_load_from_buf(t_grid* grid, char* buf) { size_t rows = 0; size_t elem_cnt = 0; char* line_r = NULL; char* line = strtok_r(buf, "\n", &line_r); while( line != NULL ) { char* save_pointer = NULL; // primary char* elem_of_line = strtok_r(line, " ", &save_pointer); if(NULL != to_skip && strstr(to_skip, elem_of_line)) { line = strtok_r(NULL, "\n", &line_r); }else{ while( elem_of_line != NULL ) { if(debug == 1) { printf("%s\n",elem_of_line); } if(resolve_symlinks == 1 && is_symlink(elem_of_line)) { char* resolvBuf = realpath(elem_of_line, NULL); if(NULL != resolvBuf) { char* dest = malloc(sizeof(char)*strlen(resolvBuf)+1); if(NULL == tofree) { tofree = malloc(sizeof(char*)); if(NULL == tofree) { fprintf(stderr, _("malloc failed\n")); free(resolvBuf); exit(1); } }else{ char** np = realloc(tofree, (tofree_c+1)*sizeof(char*)); if(NULL == np) { fprintf(stderr, _("realloc failed\n")); free(resolvBuf); exit(1); }else{ tofree = np; } } tofree[tofree_c++] = dest; strncpy(dest, resolvBuf, strlen(resolvBuf)+1); free(resolvBuf); grid->elem[elem_cnt].value = dest; } }else{ grid->elem[elem_cnt].value = elem_of_line; } elem_of_line = strtok_r(NULL, " ", &save_pointer); ++elem_cnt; } line = strtok_r(NULL, "\n", &line_r); ++rows; } } if(rows > 0) { grid->rows = rows; grid->columns = elem_cnt/rows; }else{ fprintf(stderr, _("Can't load at least one row from buffer\n")); return 0; } return 1; } int get_grid_dims(const char* cBuf, size_t* grows, size_t* gcols) { size_t rows = 0; size_t elem_cnt = 0; char* buf = strdup(cBuf); char* line_r = NULL; char* line = strtok_r(buf, "\n", &line_r); while( line != NULL ) { char* save_pointer = NULL; // primary char* elem_of_line = strtok_r(line, " ", &save_pointer); if(NULL != to_skip && strstr(to_skip, elem_of_line)) { line = strtok_r(NULL, "\n", &line_r); }else{ while( elem_of_line != NULL ) { elem_of_line = strtok_r(NULL, " ", &save_pointer); ++elem_cnt; } line = strtok_r(NULL, "\n", &line_r); ++rows; } } free(buf); if(rows > 0) { *grows = rows; *gcols = elem_cnt/rows; return 1; }else{ fprintf(stderr, _("Can't load at least one row from buffer\n")); return 0; } } lsmount-0.2.3/src/lsmgrid.h000066400000000000000000000011041341416302100156050ustar00rootroot00000000000000#ifndef LSMGRID_H #define LSMGRID_H #include char** tofree; size_t tofree_c; size_t column_length[7]; typedef struct t_grid t_grid; typedef struct t_elem t_elem; struct t_grid { size_t columns; // should be fix size_t rows; t_elem* elem; }; struct t_elem { char* value; }; t_grid* grid_create(size_t columns, size_t rows); void grid_destroy(t_grid* grid); void grid_print(t_grid* grid); void grid_analyse(t_grid* grid); int grid_load_from_buf(t_grid* grid, char* buf); int get_grid_dims(const char* buf, size_t* grows, size_t* gcols); #endif lsmount-0.2.3/src/lsmount.c000066400000000000000000000054131341416302100156470ustar00rootroot00000000000000#include #include #include #include #include // stat S_ISLINK lstat .. #include // getpwuid #include #include #include "lsmount.h" #include "lsmgrid.h" #include "lsmcolors.h" #include "options.h" #include "helper.h" #ifdef _POSIX_VERSION #if _POSIX_VERSION < 200809L #error at least POSIX version 200809 required #endif #else #error POSIX support required. #endif int main(int argc, char** argv) { setlocale(LC_ALL, ""); bindtextdomain("lsmount", "/usr/share/locale"); textdomain("lsmount"); // init color array initcolors(); // init parameter variables debug = 0; use_color = 0; show_unused = 0; resolve_symlinks = 0; use_alignment = 0; vertical = 0; mnt_file = "/proc/mounts"; const char* conf_file1 = "/etc/lsmountrc"; char* conf_file2; const struct passwd* pw = getpwuid(getuid()); const char* homedir = pw->pw_dir; // get absolute conf_file2 path in homedir if(-1 == asprintf(&conf_file2, "%s%s", homedir, "/.config/lsmount.rc")) { fprintf(stderr,_("failure by generating conf_file2 path\n")); free(conf_file2); exit(1); } // get options if(!access(conf_file1, R_OK)) { readconffile(conf_file1); } if(!access(conf_file2, R_OK)) { readconffile(conf_file2); } free(conf_file2); if(0 != parsecmd(argc, argv)) { exit(1); } if(NULL == mnt_file) { mnt_file = MNT_FILE; } if(debug == 1) { printf( "debug: %d\n" "use_color: %d\n" "show_unused: %d\n" "resolve_symlinks: %d\n" "use_alignment: %d\n" "vertical: %d\n" "to_skip: %s\n" "mnt_file: %s\n", debug, use_color, show_unused, resolve_symlinks, use_alignment, vertical, to_skip, mnt_file ); } // read file to buffer char* filebuf = read_file_to_buf(mnt_file); // evaluate grid dimensions size_t grows = 0; size_t gcols = 0; if(!get_grid_dims(filebuf, &grows, &gcols)) { fprintf(stderr, _("can't get grid dimensions\n")); free(conf_file2); free(filebuf); free(to_skip); exit(1); } if(debug == 1) { printf( "grows: %ld\n" "gcols: %ld\n", grows, gcols ); } if(gcols != 6) { fprintf( stderr, _("\"%s\" doesn't seem to be a valid input file for lsmount\n"), mnt_file ); free(conf_file2); free(filebuf); free(to_skip); exit(1); } // create grid t_grid* grid = grid_create(gcols, grows); // load data to grid if(!grid_load_from_buf(grid, filebuf)) { fprintf(stderr, _("load to grid failed (%s)\n"), strerror(errno)); free(conf_file2); free(filebuf); free(to_skip); exit(1); } grid_print(grid); grid_destroy(grid); free(filebuf); // is used by strtok elements, do not free earlier free(to_skip); exit(0); } lsmount-0.2.3/src/lsmount.h000066400000000000000000000001711341416302100156500ustar00rootroot00000000000000#ifndef LSMOUNT_H #define LSMOUNT_H #include #include #define _(STRING) gettext(STRING) #endif lsmount-0.2.3/src/options.c000066400000000000000000000164511341416302100156450ustar00rootroot00000000000000#include #include #include #include #include #include // because terminfo manpages said so... #include #include #include "lsmount.h" #include "options.h" #include "lsmcolors.h" int parsecmd(int argc, char** argv) { int opt; static struct option long_options[] = { {"use-alignment", no_argument, NULL, 'a'}, {"dont-use-alignment", no_argument, NULL, 'A'}, {"use-color", optional_argument, NULL, 'c'}, {"dont-use-color", no_argument, NULL, 'C'}, {"debug", no_argument, NULL, 'd'}, {"dont-debug", no_argument, NULL, 'D'}, {"use-file", required_argument, NULL, 'f'}, {"dont-use-file", no_argument, NULL, 'F'}, {"help", no_argument, NULL, 'h'}, {"dont-help", no_argument, NULL, 'H'}, {"resolv-symlinks", no_argument, NULL, 'l'}, {"dont-resolv-symlinks", no_argument, NULL, 'L'}, {"skip", required_argument, NULL, 's'}, {"dont-skip", no_argument, NULL, 'S'}, {"show-unused", no_argument, NULL, 'u'}, {"dont-show-unused", no_argument, NULL, 'U'}, {"print-vertical", no_argument, NULL, 'v'}, {"dont-print-vertical", no_argument, NULL, 'V'}, {"set-colors", required_argument, NULL, 'x'}, {"dont-set-colors", no_argument, NULL, 'X'}, {NULL, 0, NULL, '\0'} }; while((opt = getopt_long(argc, argv, "aAcCdDf:FhHlLs:SuUvVx:X", long_options, NULL)) != -1) { switch(opt) { case 'a': use_alignment = 1; break; case 'A': use_alignment = 0; break; case 'c': if(argv && argv[optind] && strcmp(argv[optind],"auto") == 0) { use_color = colorcap(); }else{ use_color = 1; } break; case 'C': use_color = 0; break; case 'd': debug = 1; break; case 'D': debug = 0; break; case 'f': mnt_file = optarg; break; case 'F': mnt_file = MNT_FILE; break; case 'h': usage(0); break; case 'H': // just to be consistent exit(1); break; case 'l': resolve_symlinks = 1; break; case 'L': resolve_symlinks = 0; break; case 's': if(optarg) { size_t optsize = strlen(optarg)+1; if(NULL != to_skip) { free(to_skip); // if set by conf } to_skip = (char*)malloc(optsize); strncpy(to_skip, optarg,optsize); } break; case 'S': if(NULL != to_skip) { free(to_skip); // if set by conf } to_skip = calloc(1,1); // empty string break; case 'u': show_unused = 1; break; case 'U': show_unused = 0; break; case 'v': vertical = 1; break; case 'V': vertical = 0; break; case 'x': if(optarg) { char* value; char* subopts; char* const tokens[] = { NULL // not searching for tokens, want the whole string }; subopts = optarg; uint8_t i=0; while(*subopts != '\0') { if(-1 != getsubopt(&subopts, tokens, &value)) { printf(_("recognized token where I shouldn't\n")); exit(1); } colors[i] = colortoesc(value); ++i; } if(i == 1) { printf(_("unknown argument for option set-color(c)\n")); if(NULL != to_skip) { free(to_skip); } exit(1); }else if(i != 6) { printf(_("wrong number of arguments for option use-color(c)\n")); if(NULL != to_skip) { free(to_skip); } exit(1); } } break; case 'X': initcolors(); break; default: usage(1); } } return 0; } int readconffile(const char* config_file) { config_t cfg; int value; const char* strvalue = NULL; config_init(&cfg); if (!config_read_file(&cfg, config_file)) { printf( _("Can't read config-file %s:%d - %s\n"), config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg) ); config_destroy(&cfg); return -1; } if(config_lookup_bool(&cfg, "debug", &value)) { debug = (uint8_t)value; } if(config_lookup_string(&cfg, "skip", &strvalue)) { if(strvalue) { to_skip = (char*)malloc(strlen(strvalue)+1); strcpy(to_skip,strvalue); } } if(config_lookup_bool(&cfg, "use-color", &value)) { use_color = (uint8_t)value; }else if(config_lookup_string(&cfg, "use-color", &strvalue)) { if(strvalue) { if(!strcmp(strvalue,"auto")) { use_color = colorcap(); }else{ printf(_("unknown argument %s for option use-color(c)\n"), strvalue); exit(1); } }else{ use_color = 0; } } if(config_lookup_string(&cfg, "set-colors", &strvalue)) { if(strvalue) { uint16_t i = 0; char* strvalue_cpy = strdup(strvalue); char* token = NULL; token = strtok(strvalue_cpy, ","); while(NULL != token) { colors[i] = colortoesc(token); token = strtok(NULL, ","); ++i; } free(strvalue_cpy); } } if(config_lookup_bool(&cfg, "show-unused", &value)) { show_unused = (uint8_t)value; } if(config_lookup_bool(&cfg, "resolve-symlinks", &value)) { resolve_symlinks = (uint8_t)value; } if(config_lookup_bool(&cfg, "use-alignment", &value)) { use_alignment = (uint8_t)value; } if(config_lookup_bool(&cfg, "vertical", &value)) { vertical = (uint8_t)value; } config_destroy(&cfg); return 0; } uint8_t colorcap(void) { int* errret = NULL; int ret = setupterm(NULL, 1, errret); // will leak mem (curses sucks) if(0 != ret) { if(NULL != errret) { if(1 == *errret) { fprintf(stderr, _("Terminal is a hardcopy type\n")); }else if(0 == *errret) { fprintf(stderr, _("Terminal could not be found, or it is a generic type\n")); }else if(-1 == *errret) { fprintf(stderr, _("terminfo database could not be found\n")); }else{ fprintf(stderr, _("something strange happened while evaluating terminfo\n")); } del_curterm(cur_term); return 0; }else{ fprintf(stderr, _("something strange happened while evaluating terminfo\n")); del_curterm(cur_term); return 0; } }else{ if(tigetnum("colors") >= 8) { del_curterm(cur_term); return 1; }else{ del_curterm(cur_term); return 0; } } } void usage (int status) { puts(_("Usage: lsmount [options]\n" "\n" "Options:\n" " -a, --use-alignment align columns\n" " -c, --use-color use colors\n" " -d, --debug show debug outputs\n" " -f, --use-file use another input file\n" " -h, --help show this help\n" " -l, --resolv-symlinks resolv device symlinks\n" " -s, --skip skip devices\n" " -u, --show-unused show unused columns\n" " -v, --print-vertical vertical output\n" " -x, --set-colors set output colors\n" "\n" "all short options can be inverted by using the uppercase letter,\n" "the longopts can be inverted by adding dont- in front.\n" "\n" "Version: v0.2.3\n" "License: ISC\n") ); free(to_skip); exit(status); } lsmount-0.2.3/src/options.h000066400000000000000000000006761341416302100156540ustar00rootroot00000000000000#ifndef OPTIONS_H #define OPTIONS_H #include // parameter variables uint8_t debug; uint8_t use_color; uint8_t show_unused; uint8_t resolve_symlinks; uint8_t use_alignment; uint8_t vertical; char* to_skip; char* mnt_file; #ifndef MNT_FILE #define MNT_FILE "/proc/mounts" #endif int checkconf(void); uint8_t colorcap(void); int parsecmd(int argc, char** argv); int readconffile(const char* conf_file); void usage(int status); #endif