Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

And on the seventh day, He exited from append mode.


devel / alt.msdos.batch / Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files?

SubjectAuthor
o Re: How to insert contents of a file (or a line of text) at a givenHerbert Kleebauer

1
Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files?

<tnsu3b$941$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=303&group=alt.msdos.batch#303

  copy link   Newsgroups: alt.comp.os.windows-10 alt.comp.microsoft.windows alt.msdos.batch
Path: i2pn2.org!i2pn.org!aioe.org!zgxKd6WPKWnh43abzJ3RsQ.user.46.165.242.91.POSTED!not-for-mail
From: klee@unibwm.de (Herbert Kleebauer)
Newsgroups: alt.comp.os.windows-10,alt.comp.microsoft.windows,alt.msdos.batch
Subject: Re: How to insert contents of a file (or a line of text) at a given
location inside hundreds of text files?
Date: Tue, 20 Dec 2022 19:15:06 +0100
Organization: Aioe.org NNTP Server
Message-ID: <tnsu3b$941$1@gioia.aioe.org>
References: <tnp4n3$jrm$1@gioia.aioe.org> <tnp59a$7l7n$1@dont-email.me>
<tnpek5$8f19$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="9345"; posting-host="zgxKd6WPKWnh43abzJ3RsQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: de-DE, en-US
 by: Herbert Kleebauer - Tue, 20 Dec 2022 18:15 UTC

On 19.12.2022 11:32, Paul wrote:

> With C, there would be a temptation to write some
> low level text handlers, that a textual processor
> would already have. Maybe you can find a library for C
> to act as an assistant, so it's not an impossibility.

Just searched for a small C compiler which doesn't need
to be installed so you can store it on an USB stick and
use it on any computer.

https://download.savannah.gnu.org/releases/tinycc/
https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.27-win32-bin.zip

Just put the content of the zip file in a new folder
and all you have to do is:

tcc your_program.c

It directly creates the binary your_program.exe

And here a small C program which inserts text after
a given number of lines in a file:

________________________________________________________

/* usage: ins infile outfile */
/* after line number LINE the text TEXT is inserted */

#define LINE 5
#define TEXT "user\npass\n"

/************************************************************************
external functions used: getc(); putc(); fopen(); fclose(); exit();
************************************************************************/

#include <stdio.h>
FILE *in, *out, *fopen();

void out_string();
void print_string();
void ende();
void exit();

main(nargs,args) int nargs; char *args[];
{if (nargs!=3) ende(1);
in = fopen(args[1],"rb"); if (in==NULL) ende(2);
out = fopen(args[2],"wb"); if (out==NULL) ende(3);

int i,n=0;
while ( (i=getc(in)) != EOF)
{putc(i,out);
if (i == 10) n++;
if (n == LINE) {n++; out_string(TEXT);}
}
ende(0);
}

void out_string(p) char *p; {while (*p) putc(*p++,out);}
void print_string(p) char *p; {while (*p) putc(*p++,stdout);}

void ende(i) int i;
{static char *(meld[]) = {
/* 0 */ "no errors" ,
/* 1 */ "usage: ins infile outfile" ,
/* 2 */ "can't open input file" ,
/* 3 */ "can't open output file" ,
/* 4 */ "you never should read this" ,
/* 5 */ "you never should read this" ,
/* 6 */ "you never should read this" ,
};

print_string("\n"); print_string(meld[i]); print_string("\n");
if (in!=NULL) fclose(in);
if (out!=NULL) fclose(out);
exit(0);
}

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor