Hi everybody (and especially you, Andy),
How can someone exchange some source block file with someone else?
I mean: suppose I write an interesting program and I want to share it,
how can some other ForthOS user put it into his system?
A solution I could think of is making use of dd under Linux/Unix, but
a problem arise: I should know **exactly** the address where either put
the data or from where retrieve the data, to avoid, in the first case,
rewriting over existing data, and so I'd need a fast way to calculate
the free space into ForthOS, I mean a way to obtain a series of
contiguous block marked as free, along with an offset to them for dd.
Not to mention the fact that I may have a "file" under Linux, to
transfer as "block" under ForthOS, or a "block with shadows" under
ForthOS that I may want as "file" under another OS, and of course some
programs to convert from one format to another.
I adapted the Albert van der Horst files (he's the maintainer of
ciforth), files that operate on a classic 64x16 screen, to be used under
ForthOS 80x25 screen with shadows, and I allege them (they are not
completely tested, though). Do you find them useful?
Of course, there may be other solutions, easier and maybe already built
into the source, but I couldn't take the time to read ALL that jazz.
Any other suggestion?
Antonio Maschio
/* $Id: toblock.c,v 4.1 2002/10/17 13:44:31 albert Exp $ */
/* Copyright(2000): Albert van der Horst, HCC FIG Holland by GNU Public License */
#include <stdio.h>
#include <string.h>
#define CPL 4096
#define LINE 80
int line = 0;
char *progname;
void error(char *message)
{
fprintf(stderr, "Error in program %s\n"
" at input line %d\n"
" %s\n", progname, line, message);
exit(1);
}
int main( int argc , char **argv )
{
int count = 0;
int i;
/* One extra for the '\n', one for the '\000', and one to detect
* oversized lines */
char buffer[CPL+3];
int ch, part;
part = 0;
progname = argv[0];
while(NULL != fgets(buffer, CPL+3, stdin))
{
line++;
count = strlen(buffer);
if ( CPL < count ) error("line too long");
buffer[--count] = '\000'; /* Remove '\n' */
for(i=0; i<(((int)(count/LINE))+1)*LINE-1; i++)
putchar(i<count?buffer[i]:' ');
part += LINE;
/* first block */
if(part == 2000){
putchar('\n');
//part = 0;
}
/* shadow block + blocl control data */
else if (part == 4000) {
int q;
putchar('\n');
part = 0;
/* put fake block control data */
for (q = 0; q < 96; q++)
putchar(' ');
}
else putchar(i+1<count?buffer[i+1]:' ');
}
return 0;
}
/* $Id: fromblock.c,v 4.1 2002/10/17 13:44:04 albert Exp $ */
/* Copyright(2000): Albert van der Horst, HCC FIG Holland by GNU Public License
Copyright(2005): Antonio Maschio, ForthOS adapted by GNU Public License */
#include <stdio.h>
#include <string.h>
/* Tabs are not printable, I think. ALbert */
#define isrealprint(a) (isprint(a) && 9 != a )
#define LINE 80
main(char **argv, int argc)
{
int count = 0;
int ch, part;
static int q = 0;
part = 0;
while(EOF !=(ch=getchar())) {
char buffer[LINE];
char bufferT[96];
/* escape block control bytes */
if (part == 4000-LINE) {
q++;
if (q == 96) {
part = 0;
q = 0;
}
}
/* put block data */
else buffer[count++] = isrealprint(ch)?ch:' ';
if ( LINE == count) {
part += count;
int i;
if(buffer[count-1] = '\n') count--;
do {
count -= 1;
} while( ' ' == buffer[count-1] );
for(i=0; i<count; i++) putchar(buffer[i]);
putchar('\n');
count = 0;
}
}
return 0;
}
Received on Wed, 06 Apr 2005 16:44:21 +0200
This archive was generated by hypermail 2.1.8 : Tue Sep 26 2006 - 09:03:06 PDT