Re: Perl scripts that need rewiting - Any volunteers?

2002-06-27 Thread Mark Murray

 Hiya

Yo!

 Here's the updated version of vidfont/kbdmap.  The changes are:
 
 WARNS=6 clean
 80 columns max
 Now uses 'mkstemp()' rather than 'mktemp()'
 Fixed a couple of dumb bugs
 Copyrights added
 Removed '{}' from single lines
 Default strings now in vidfont.h

Good!

I'll check out and commit RSN. :-)

Thanks a lot!

M
-- 
o   Mark Murray
\_
O.\_Warning: this .sig is umop ap!sdn

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-26 Thread Jonathan Belson

Hiya


Here's the updated version of vidfont/kbdmap.  The changes are:

WARNS=6 clean
80 columns max
Now uses 'mkstemp()' rather than 'mktemp()'
Fixed a couple of dumb bugs
Copyrights added
Removed '{}' from single lines
Default strings now in vidfont.h

Cheers,


--Jon

http://www.witchspace.com


/*-
 * Copyright (c) 2002 Jonathan Belson [EMAIL PROTECTED]
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include sys/queue.h
#include sys/syslimits.h
#include sys/types.h

#include assert.h
#include ctype.h
#include dirent.h
#include stdio.h
#include stdlib.h
#include string.h
#include stringlist.h
#include unistd.h

#include vidfont.h


static const char *lang_default = DEFAULT_LANG;
static const char *font;
static const char *lang;
static const char *program;
static const char *keymapdir = DEFAULT_KEYMAP_DIR;
static const char *fontdir = DEFAULT_FONT_DIR;
static const char *sysconfig = DEFAULT_SYSCONFIG;
static const char *font_default = DEFAULT_FONT;
static const char *font_current;
static const char *dir;
static const char *menu = ;

static int x11;
static int show;
static int verbose;
static int print;


struct keymap {
char*desc;
char*keym;
int mark;
SLIST_ENTRY(keymap) entries;
};
static SLIST_HEAD(slisthead, keymap) head = SLIST_HEAD_INITIALIZER(head);


/*
 * Get keymap entry for 'key', or NULL of not found
 */
static struct keymap *
get_keymap(const char *key)
{
struct keymap *km;

SLIST_FOREACH(km, head, entries) {
if (!strcmp(km-keym, key))
return km;
}

return NULL;
}

/*
 * Count the number of keymaps we found
 */
static int
get_num_keymaps(void)
{
struct keymap *km;
int count = 0;

SLIST_FOREACH(km, head, entries) {
count++;
}

return count;
}

/*
 * Remove any keymap with given keym
 */
static void
remove_keymap(const char *keym)
{
struct keymap *km;

SLIST_FOREACH(km, head, entries) {
if (!strcmp(keym, km-keym)) {
SLIST_REMOVE(head, km, keymap, entries);
free(km);
break;
}
}
}

/*
 * Add to hash with 'key'
 */
static void
add_keymap(const char *desc, int mark, const char *keym)
{
struct keymap *km, *km_new;

/* Is there already an entry with this key? */
SLIST_FOREACH(km, head, entries) {
if (!strcmp(km-keym, keym)) {
/* Reuse this entry */
free(km-desc);
km-desc = strdup(desc);
km-mark = mark;
return;
}
}

km_new = (struct keymap *) malloc (sizeof(struct keymap));
km_new-desc = strdup(desc);
km_new-keym = strdup(keym);
km_new-mark = mark;

/* Add to keymap list */
SLIST_INSERT_HEAD(head, km_new, entries);
}

/*
 * Figure out the default language to use.
 */
static const char *
get_locale(void)
{
const char *locale;

if ((locale = getenv(LC_ALL)) == NULL 
(locale = getenv(LC_CTYPE)) == NULL 
(locale = getenv(LANG)) == NULL)
locale = lang_default;

/* Check for alias */
if (!strcmp(locale, C))
locale = DEFAULT_LANG;

return locale;
}

/*
 * Extract filename part
 */
static const char *
extract_name(const char *name)
{
char *p;

p = strrchr(name, '/');
if (p != NULL  p[1] != '\0')
return p + 1;

return name;
}

/*
 * Return file extension or NULL
 */
static char *

Re: Perl scripts that need rewiting - Any volunteers?

2002-06-25 Thread Mark Murray

  o Please shorten any long line or comment to less than 80 columns
 
 This is quite tricky when using 8 character tabs.  Is 4 character indent
 okay for userland source?

Real tabs are best. Look at style(9) for ways to break the long
lines.

It is ok to break very long
lines like this;

  o Please do not use mktemp(); use mkstemp() instead.
 
 I used mktemp() to get a filename to redirect to, eg.
 
 /* Improvised example */
 char *cmd;
 asprintf(cmd, prog  %s, mktemp(blah));
 system(cmd);
 free(cmd);

BIG security hole. Someone can exploit a race to compromise this.

 I couldn't see a simple way around this, any clues?

How's this?

int handle;
template = /tmp/mumble;
char *cmd;
handle = mkstemp(template); // template is modified
asprintf(cmd, prog  %s, template);
system(cmd);
close(handle); // bye-bye file

M
-- 
o   Mark Murray
\_
O.\_Warning: this .sig is umop ap!sdn

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-25 Thread Sheldon Hearn

On (2002/06/25 10:20), Mark Murray wrote:

 How's this?
 
 int handle;
 template = /tmp/mumble;
 char *cmd;
 handle = mkstemp(template); // template is modified
 asprintf(cmd, prog  %s, template);
 system(cmd);
 close(handle); // bye-bye file

It would be failsafe if you tested that mkstemp() had not returned an
error.

Ciao,
Sheldon.

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-25 Thread Alfred Perlstein

* Mark Murray [EMAIL PROTECTED] [020625 02:26] wrote:
 
  I couldn't see a simple way around this, any clues?
 
 How's this?
 
 int handle;
 template = /tmp/mumble;
 char *cmd;
 handle = mkstemp(template); // template is modified
 asprintf(cmd, prog  %s, template);
 system(cmd);
 close(handle); // bye-bye file

Kinda buggy. :)

int fd, status;
char *template = strdup(/tmp/mumble);
if (template == NULL)
/* ERROR */
fd = mkstemp(template);
if (fd == -1) {
free(template);
/* ERROR */
}
asprintf(cmd, prog  %s, template);
status = system(cmd);
unlink(template);
free(cmd);
free(template);
close(fd);
/* if normal exit, return true if exit code was 0 (success) */
return (WIFEXITED(status) ? WEXITSTATUS(status) == EXIT_SUCCESS : 0);

-- 
-Alfred Perlstein [[EMAIL PROTECTED]]
'Instead of asking why a piece of software is using 1970s technology,
 start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-25 Thread Mark Murray

 Kinda buggy. :)

Ya, ya, ya. :-)

That was the concept model. The actual author can make it robust. :-)

M
-- 
o   Mark Murray
\_
O.\_Warning: this .sig is umop ap!sdn

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-24 Thread Jonathan Belson

Mark Murray wrote:

Okay, here's my vidfont/kbdmap rewrite for review.  Any feedback
is welcome, the same goes for bug reports :-)
 
 Cool, thank you very much!
 
 Some comments:
 
 o Please put a copyright on the top of this. By preference, please use
   /usr/share/examples/etc/bsd-style-copyright.
 
 o The code style is generally good, but please don't put braces around
   single lines of code, ie use
   for (;;)
   stuff;
   rather than
   for (;;) {
   stuff;
   }
 
 o Please put all the macro strings like default font and directories into
   macros and #include those from (say) vidfont.h.

All done.

 o Please shorten any long line or comment to less than 80 columns

This is quite tricky when using 8 character tabs.  Is 4 character indent
okay for userland source?

 o Please do not use mktemp(); use mkstemp() instead.

I used mktemp() to get a filename to redirect to, eg.

/* Improvised example */
char *cmd;
asprintf(cmd, prog  %s, mktemp(blah));
system(cmd);
free(cmd);

I couldn't see a simple way around this, any clues?

 o Please make this WARNS=6 clean as far as is possible.

Done.

Cheers,


--Jon

http://www.witchsapce.com


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-24 Thread Cyrille Lefevre

On Mon, Jun 24, 2002 at 08:46:22PM +0100, Jonathan Belson wrote:
 Mark Murray wrote:
 o Please do not use mktemp(); use mkstemp() instead.
 
 I used mktemp() to get a filename to redirect to, eg.
 
 /* Improvised example */
 char *cmd;
 asprintf(cmd, prog  %s, mktemp(blah));
 system(cmd);
 free(cmd);
 
 I couldn't see a simple way around this, any clues?
int fd = mkstemp (blah);
asprintf(cmd, prog  /dev/fd/%d, fd);

I don't look at the code, but how about popen(3) ?

Cyrille.
-- 
Cyrille Lefevre mailto:[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-23 Thread Mark Murray

 Mark Murray wrote:
 These seem to be the same program.  I'll take this if there are no
 objections. 
  
  You have it!
 
 Okay, here's my vidfont/kbdmap rewrite for review.  Any feedback
 is welcome, the same goes for bug reports :-)

Cool, thank you very much!

Some comments:

o Please put a copyright on the top of this. By preference, please use
  /usr/share/examples/etc/bsd-style-copyright.

o The code style is generally good, but please don't put braces around
  single lines of code, ie use
  for (;;)
stuff;
  rather than
  for (;;) {
stuff;
  }

o Please put all the macro strings like default font and directories into
  macros and #include those from (say) vidfont.h.

o Please shorten any long line or comment to less than 80 columns

o Please do not use mktemp(); use mkstemp() instead.

o Please make this WARNS=6 clean as far as is possible.

Thanks!

M
-- 
o   Mark Murray
\_
O.\_Warning: this .sig is umop ap!sdn

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-06-14 Thread Jonathan Belson

Mark Murray wrote:
These seem to be the same program.  I'll take this if there are no
objections. 
 
 You have it!

Okay, here's my vidfont/kbdmap rewrite for review.  Any feedback
is welcome, the same goes for bug reports :-)

Cheers,


--Jon

http://www.witchspace.com



#include sys/queue.h
#include sys/types.h

#include assert.h
#include ctype.h
#include dirent.h
#include stdio.h
#include stdlib.h
#include string.h
#include stringlist.h
#include unistd.h


static char *lang_default = en;
static char *font;
static char *lang;
static const char *program;
static char *keymapdir = /usr/share/syscons/keymaps;
static char *fontdir = /usr/share/syscons/fonts;
static char *sysconfig = /etc/rc.conf;
static char *font_default = cp437-8x16.fnt;
static char *font_current;
static char *dir;
static const char *menu = ;

static int x11;
static int show;
static int verbose;
static int print;


struct keymap {
char*desc;
char*keym;
int mark;
SLIST_ENTRY(keymap) entries;
};
static SLIST_HEAD(slisthead, keymap) head = SLIST_HEAD_INITIALIZER(head);


/*
 * Get keymap entry for 'key', or NULL of not found
 */
struct keymap *
get_keymap(const char *key)
{
struct keymap *km;

SLIST_FOREACH(km, head, entries) {
if (!strcmp(km-keym, key)) {
return km;
}
}

return NULL;
}

/*
 * Count the number of keymaps we found
 */
static int
get_num_keymaps(void)
{
struct keymap *km;
int count = 0;

SLIST_FOREACH(km, head, entries) {
count++;
}

return count;
}

/*
 * Remove any keymap with given keym
 */
static void
remove_keymap(const char *keym)
{
struct keymap *km;

SLIST_FOREACH(km, head, entries) {
if (!strcmp(keym, km-keym)) {
SLIST_REMOVE(head, km, keymap, entries);
free(km);
break;
}
}
}

/*
 * Add to hash with 'key'
 */
void
add_keymap(const char *desc, int mark, const char *keym)
{
struct keymap *km, *km_new;

/* Is there already an entry with this key? */
SLIST_FOREACH(km, head, entries) {
if (!strcmp(km-keym, keym)) {
/* Reuse this entry */
free(km-desc);
km-desc = strdup(desc);
km-mark = mark;
return;
}
}

km_new = (struct keymap *) malloc (sizeof(struct keymap));
km_new-desc = strdup(desc);
km_new-keym = strdup(keym);
km_new-mark = mark;

/* Add to keymap list */
SLIST_INSERT_HEAD(head, km_new, entries);
}

/*
 * Figure out the default language to use.
 */
static char *
get_locale(void)
{
char *locale;

locale = getenv(LC_ALL);
if (locale == NULL) {
locale = getenv(LC_CTYPE);
if (locale == NULL) {
locale = getenv(LANG);
if (locale == NULL) {
locale = lang_default;
}
}
}

/* Check for alias */
if (!strcmp(locale, C)) {
locale = en;
}

return locale;
}

/*
 * Extract filename part
 */
static const char *
extract_name(char *name)
{
char *p;

p = strrchr(name, '/');
if (p != NULL  p[1] != '\0') {
return p + 1;
} 

return name;
}

/*
 * Return file extension or NULL
 */
static char *
get_extension(const char *name)
{
char *p;

p = strrchr(name, '.');

if (p != NULL  p[1] != '\0') {
return p;
}

return NULL;
}

/*
 * Read font from /etc/rc.conf else return default.
 * Freeing the memory is the caller's responsibility.
 */
static char *
get_font(void)
{
char line[256], buf[20];
char *font = NULL;

FILE *fp = fopen(sysconfig, r);
if (fp) {
while (fgets(line, sizeof(line), fp)) {
int a, b, matches;

if (line[0] == '#') {
continue;
}

matches = sscanf(line,  font%dx%d = \%20[-.0-9a-zA-Z_], a, 
b, buf);
if (matches==3) {
if (strcmp(buf, NO)) {
if (font) {
free(font);
}
font = (char *) malloc(strlen(buf) + 1);
strcpy(font, buf);
}
}
}
} else {
printf(Could not open %s for reading\n, sysconfig);
}

return font;
}

/*
 * 

Re: Perl scripts that need rewiting - Any volunteers?

2002-05-10 Thread Mike Makonnen

On Thu, 2002-05-09 at 07:41, Mark Murray wrote:
  On Thu, 2002-05-09 at 03:57, Mark Murray wrote:
  
   /usr/sbin/rmuser  Wrapper round pw userdel?
  
  I took this one while the discussion was going on the past couple of
  days. It's at:
  http://home.pacbell.net/makonnen/rmuser.sh
  
  It also implements new functionality-- you can now specify a list of
  usernames on the command line or in a file (-f option) instead of
  deleting them one at a time.
  
  I guess I might as well take adduser too.
 
 Manpages too, please! :-) If you don't know *roff, no problem, write
 the words, and our friedly and excellent docs people will mark it up
 for you.

The problem with writing man pages is, if you don't do it often enough
you keep having to relearn it every time you do (which is why I wised up
after about the third time or so this happened to me I created a cheat
sheet). What would be cool is if the man pages were somehow integrated
into the FreeBSD Documentation Project. That way I have to remember only
the SGML tags.
(yes, yes, I know: patches please? 8-)

In any case, here's a proper patch (man page and all):
http://home.pacbell.net/makonnen/rmuser.diff


Cheers,
Mike Makonnen

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-05-10 Thread David O'Brien

On Fri, May 10, 2002 at 01:56:16AM -0600, Mike Makonnen wrote:
 The problem with writing man pages is, if you don't do it often enough
 you keep having to relearn it every time you do (which is why I wised up

/usr/share/examples/mdoc/example.{1,3,4}

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-05-10 Thread Mike Makonnen

On Fri, 2002-05-10 at 02:56, David O'Brien wrote:
 On Fri, May 10, 2002 at 01:56:16AM -0600, Mike Makonnen wrote:
  The problem with writing man pages is, if you don't do it often enough
  you keep having to relearn it every time you do (which is why I wised up
 
 /usr/share/examples/mdoc/example.{1,3,4}
 

Thanks! I should have guessed.

Cheers,
Mike Makonnen.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-05-10 Thread Michael Lucas

On Fri, May 10, 2002 at 01:56:16AM -0600, Mike Makonnen wrote:
 The problem with writing man pages is, if you don't do it often enough
 you keep having to relearn it every time you do (which is why I wised up
 after about the third time or so this happened to me I created a cheat
 sheet). What would be cool is if the man pages were somehow integrated
 into the FreeBSD Documentation Project. That way I have to remember only
 the SGML tags.

We discussed the possibility of doing this at the last BSDCon BoF.
Other UNIXes (i.e., Sun IIRC) are already doing this, using
proprietary tools.

Short answer: our tools just aren't there yet, but we're hoping.

==ml

-- 
Michael Lucas   [EMAIL PROTECTED], [EMAIL PROTECTED]
http://www.oreillynet.com/pub/q/Big_Scary_Daemons

   Absolute BSD:   http://www.nostarch.com/abs_bsd.htm

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-05-09 Thread Riccardo Torrini

On 09-May-2002 (15:38:45/GMT) Mark Murray wrote:

 I tryed this one.  I'm not a committer, just a volunteer  :-)

 You're on!  Please put appropriate (c) on this (Preferably
 2-clause BSD license) and I'll commit it for you :-)

Ahemm, I'm not sure to have done correct job.  Please review last
version of this script from my site:
ftp://castle.torrini.org/pub/FreeBSD/spkrtest-current
and modify if I miss or don't understand something  ;)
Thanks.


Riccardo.

PS: I think that man page (/usr/src/usr.sbin/spkrtest/spkrtest.8)
should be changed to remove perl(1):

# diff -u2 spkrtest.8.orig spkrtest.8
--- spkrtest.8.orig Fri Jul 13 17:36:02 2001
+++ spkrtest.8  Thu May  9 20:43:40 2002
@@ -40,5 +40,4 @@
 .Sh SEE ALSO
 .Xr dialog 1 ,
-.Xr perl 1 ,
 .Xr spkr 4
 .Sh HISTORY


or to include sh(1):

# diff -u2 spkrtest.8.orig spkrtest.8
--- spkrtest.8.orig Fri Jul 13 17:36:02 2001
+++ spkrtest.8  Thu May  9 20:58:46 2002
@@ -40,5 +40,5 @@
 .Sh SEE ALSO
 .Xr dialog 1 ,
-.Xr perl 1 ,
+.Xr sh 1 ,
 .Xr spkr 4
 .Sh HISTORY

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-05-09 Thread Mark Murray

 On 09-May-2002 (15:38:45/GMT) Mark Murray wrote:
 
  I tryed this one.  I'm not a committer, just a volunteer  :-)
 
  You're on!  Please put appropriate (c) on this (Preferably
  2-clause BSD license) and I'll commit it for you :-)
 
 Ahemm, I'm not sure to have done correct job.  Please review last
 version of this script from my site:
 ftp://castle.torrini.org/pub/FreeBSD/spkrtest-current
 and modify if I miss or don't understand something  ;)
 Thanks.

Looks fine to me!

Thanks! Commit will come later...

M
-- 
o   Mark Murray
\_
O.\_Warning: this .sig is umop ap!sdn

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Perl scripts that need rewiting - Any volunteers?

2002-05-09 Thread Peter Wemm

Mark Murray wrote:
  [bogus From: address, because people cannot be bothered to respect Reply-To
:]
  
  On Thu, May 09, 2002 at 10:57:00AM +0100, Mark Murray wrote:
   It would be acceptable to rewrite in C (C++?)
  
  NO! for rewriting in C++.  If you do, you'll soon see the consequences.
  (and that is all I am going to elude to at this time)
 
 Need info here :-). Has this to do with GCC 3.x?

Yes.  The problem is libstdc++-v3.

 (And if so, are we in trouble with groff?)

Partly.  groff isn't a big libstdc++ user.  It is mostly a C-with-classes
and almost exclusively a libc user.

Cheers,
-Peter
--
Peter Wemm - [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
All of this is for nothing if we don't go to the stars - JMS/B5


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message