1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/* This is part of um-ViewOS
* The user-mode implementation of OSVIEW -- A Process with a View
*
* umviewname.c
* uname extension to view-os (umview)
*
* Copyright 2005 Renzo Davoli University of Bologna - Italy
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* $Id: viewname.c 910 2011-01-06 12:07:48Z rd235 $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <config.h>
#include <um_lib.h>
int quiet,prompt;
void usage()
{
fprintf(stderr,
"Usage: viewname [-qp] [newname]\n"
" -q quiet mode, silent on errors\n"
" -p prompt mode, create a string for the prompt message\n"
"\n"
"This command can get or set the view name (View-OS)\n"
"\n");
exit(2);
}
int main(int argc, char *argv[])
{
int c;
struct viewinfo vi;
while (1) {
int option_index = 0;
static struct option long_options[] = {
{"quiet",0,0,'q'},
{"prompt",0,0,'p'},
{"help",0,0,'h'},
{0,0,0,0}
};
c=getopt_long(argc,argv,"pqh",long_options,&option_index);
if (c == -1) break;
switch (c) {
case 'p':
prompt=1;
break;
case 'q':
quiet=1;
break;
case 'h':
usage();
break;
}
}
if (argc - optind > 1 || (prompt && (argc - optind > 0))) {
usage();
exit(1);
}
if (argc - optind == 0) {
c=um_view_getinfo(&vi);
if (c<0) {
if (!quiet) perror("umviewname:");
exit (1);
}
if (prompt) {
if (strlen (vi.viewname) > 0)
printf("%s\n",vi.viewname);
else
printf("%s[%d:%lu]\n",vi.uname.nodename,vi.serverid,vi.viewid);
} else
printf("%s\n",vi.viewname);
} else {
c=um_setviewname(argv[1]);
if (c<0) {
if (!quiet) perror("umviewname:");
exit (1);
}
}
exit (0);
}
|