Bug#525036: dc: Feature Request: string manipulation and file i/o

2009-04-21 Thread Jack T Mudge III
Package: dc
Version: 1.06.94-3
Severity: wishlist
Tags: patch

I would like dc to be able to do some simple string manipulation and file i/o. 
I'm attaching a patch that adds the  (concatenate string), @ (split string 
into characters), and w (manipulate a file, 'wo' for open, for example) 
operations. I have also documented these changes in the man page and texinfo 
page.


Hope it helps!


-- System Information:
Debian Release: squeeze/sid
  APT prefers testing-proposed-updates
  APT policy: (500, 'testing-proposed-updates'), (500, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages dc depends on:
ii  libc6 2.9-4  GNU C Library: Shared libraries

dc recommends no packages.

dc suggests no packages.

-- no debconf information

*** /home/jakykong/dc.diff
diff -Naur dc2/bc-1.06.94/dc/dc-proto.h dc/bc-1.06.94/dc/dc-proto.h
--- dc2/bc-1.06.94/dc/dc-proto.h2005-05-25 14:13:20.0 -0700
+++ dc/bc-1.06.94/dc/dc-proto.h 2009-04-20 18:29:47.0 -0700
@@ -77,6 +77,7 @@
 extern dc_data dc_getnum DC_PROTO((int (*)(void), int, int *));
 extern dc_data dc_int2data DC_PROTO((int));
 extern dc_data dc_makestring DC_PROTO((const char *, size_t));
+extern dc_data dc_catstring DC_PROTO((dc_str, dc_str));
 extern dc_data dc_readstring DC_PROTO((FILE *, int , int));
 
 extern int dc_add DC_PROTO((dc_num, dc_num, int, dc_num *));
diff -Naur dc2/bc-1.06.94/dc/eval.c dc/bc-1.06.94/dc/eval.c
--- dc2/bc-1.06.94/dc/eval.c2006-06-04 04:04:40.0 -0700
+++ dc/bc-1.06.94/dc/eval.c 2009-04-21 09:16:02.0 -0700
@@ -90,6 +90,10 @@
  */
 static int input_pushback;
 
+/* Use for the file manipulation characters g, h, j, m, and t
+ */
+static FILE *manip_fil_fp=0;
+
 /* passed as an argument to dc_getnum */
 static int
 input_fil DC_DECLVOID()
@@ -513,6 +517,87 @@
dc_push(dc_array_get(peekc, tmpint));
}
return DC_EATONE;
+/* NOTE: adds string concatenation and split to dc */
+   case '': /* concatenate top two elements of stack as strings */
+   if(dc_pop(datum) == DC_SUCCESS) {
+   dc_data datum2;
+   if(dc_pop(datum2) == DC_SUCCESS) {
+   if(datum.dc_type == DC_STRING  datum2.dc_type 
== DC_STRING) {
+   /* concatenate the strings */
+   dc_push(dc_catstring(datum2.v.string, 
datum.v.string));
+   }
+   }
+   }
+   else
+   return DC_FAIL;
+   break;
+   case '@': /* split top element of stack into individual characters and 
push 
each onto another stack. */
+   if (peekc == EOF)
+   return DC_EOF_ERROR;
+   if (dc_pop(datum) == DC_SUCCESS  datum.dc_type == DC_STRING)
+   for(tmpint = 0; tmpint  dc_strlen(datum.v.string); 
tmpint++) {
+   dc_array_set(peekc, tmpint,
+   dc_makestring( 
dc_str2charp(datum.v.string)[tmpint], 1));
+   }
+   else
+   fprintf(stderr,
+   %s: top of stack must be string.\n,
+   progname);
+   return DC_EATONE;
+/* NOTE: adds file open/close read/write to dc, sortof. */
+   case 'w': /* do file manipulations. Just 'F' for compactness. */
+   switch (peekc)
+   {
+   case 'o': /* open file */
+   if(dc_pop(datum) == DC_SUCCESS){
+   if( datum.dc_type == DC_STRING) {
+   
puts(dc_str2charp(datum.v.string));
+   (manip_fil_fp = fopen( 
dc_str2charp(datum.v.string), r+ )) ||
+   (manip_fil_fp = fopen( 
dc_str2charp(datum.v.string), w+));
+   if( !manip_fil_fp ) 
+   fprintf(stderr, 
%s: error opening file\n, progname);
+   }
+   }
+   break;
+   case 'c': /* close file */
+   fclose(manip_fil_fp);
+   break;
+   case 'r': /* read byte, move 1 forward */
+   tmpint = fgetc(manip_fil_fp);
+   if( tmpint == EOF )
+   dc_push(dc_int2data(-1));
+   else
+ 

Bug#525036: dc: Feature Request: string manipulation and file i/o

2009-04-21 Thread John Hasler
I will forward your patch upstream.
-- 
John Hasler 
j...@dhh.gt.org
Elmwood, WI USA



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org