Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ITT small crappy tools you've made.

Name: Anonymous 2008-01-15 19:59

lol progfind


# progfind shiichan

Title:     Shiichan Post Referencing
URL:       http://dis.4chan.org/read/prog/1195857400
Posted:    2007-11-23 22:36
Last Post: 2007-11-24 14:52

Title:     SHIICHAN HAS A FATAL FLAW
URL:       http://dis.4chan.org/read/prog/1185843497
Posted:    2007-07-31 01:58
Last Post: 2007-08-03 12:56

Title:     Shiichan, read.php, Line 11
URL:       http://dis.4chan.org/read/prog/1185626900
Posted:    2007-07-28 13:48
Last Post: 2007-07-28 14:10

Title:     Shiichan needs an [img]
URL:       http://dis.4chan.org/read/prog/1185463229
Posted:    2007-07-26 16:20
Last Post: 2007-07-26 23:17

Title:     Shiichan
URL:       http://dis.4chan.org/read/prog/1181486959
Posted:    2007-06-10 15:49
Last Post: 2007-06-11 16:53

Name: Anonymous 2008-01-15 21:27

#include <cgic.h>
#include <iconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/file.h>

#define cgi_main cgiMain
#define cgi_out cgiOut
#define cgi_header_location cgiHeaderLocation
#define cgi_header_content_type cgiHeaderContentType
#define cgi_form_string cgiFormString
#define cgi_form_integer cgiFormInteger

#define MAX_POSTS 256
#define MAX_POST_LENGTH 4096
#define POSTS_FILENAME "posts.xml"
#define INDEX_FILENAME "index.html"

#define LOCK_SH 0x01
#define LOCK_EX 0x02
#define LOCK_NB 0x04
#define LOCK_UN 0x08

void build_main_page();
void clean_text(unsigned char*,unsigned char*);
int do_post();
void do_redirect();

int cgi_main(){
 if(access(POSTS_FILENAME,F_OK))
  build_main_page();
 if(do_post())
  do_redirect();
 return 0;
}

void do_redirect(){
 cgi_header_location(INDEX_FILENAME);
 return;
}

int do_post(){
 int wrote_post=0;
 char text[MAX_POST_LENGTH+1]={0};
 char text2[MAX_POST_LENGTH+1]={0};
 char text_out[MAX_POST_LENGTH*5+1]={0};
 char line[MAX_POST_LENGTH*5+29]={0};
 char post_num[32]={0};
 const char *textp=text;
 char *text2p=text2;
 int inbytesleft=strlen(text),outbytesleft=strlen(text);
 int redirect;
 FILE* post_file_in;
 FILE* post_file_out;
 cgi_form_string("text",text,MAX_POST_LENGTH+1);
 cgi_form_integer("redirect",&redirect,0);
 if(!text[0])
  return 1;
 iconv_t cd=iconv_open("UTF-8","UTF-8");
 int iconv_result=iconv(cd,&textp,&inbytesleft,&text2p,&outbytesleft);
 if(iconv_result==-1)
  return 1;
 iconv_close(cd);
 clean_text(text,text_out);
 srandomdev();
 snprintf(post_num,32,"\"%d\">",random()%MAX_POSTS);
 rename(POSTS_FILENAME,"temp");
 post_file_in=fopen("temp","r");
 post_file_out=fopen(POSTS_FILENAME,"w");
 flock(fileno(post_file_in),LOCK_EX);
 flock(fileno(post_file_out),LOCK_EX);
 while(!feof(post_file_in)){
  fgets(line,MAX_POST_LENGTH*5+29,post_file_in);
  if(strstr(line,post_num)||(strstr(line,"</posts>")&&!wrote_post)){
   fprintf(post_file_out," <post id=%s<text>%s</text></post>\n",post_num,text_out);
   wrote_post=1;
  }
  if(!strstr(line,post_num)&&!feof(post_file_in)){
   fputs(line,post_file_out);
  }
 }
 flock(fileno(post_file_in),LOCK_UN);
 flock(fileno(post_file_out),LOCK_UN);
 fclose(post_file_in);
 fclose(post_file_out);
 remove("temp");
 if(redirect)
  return 1;
 cgi_header_content_type("text/plain");
 fputs("\n\n",cgi_out);
 return 0;
}

void clean_text(unsigned char* text_in,unsigned char* text_out){
 int j,k=0;
 for(j=0;j<MAX_POST_LENGTH;j++){
  switch(text_in[j]){
   case '&':
    text_out[k++]='&';
    text_out[k++]='a';
    text_out[k++]='m';
    text_out[k++]='p';
    text_out[k++]=';';
    break;
   case '<':
    text_out[k++]='&';
    text_out[k++]='l';
    text_out[k++]='t';
    text_out[k++]=';';
    break;
   case '>':
    text_out[k++]='&';
    text_out[k++]='g';
    text_out[k++]='t';
    text_out[k++]=';';
    break;
   case '\n':
    text_out[k++]='&';
    text_out[k++]='#';
    text_out[k++]='1';
    text_out[k++]='0';
    text_out[k++]=';';
    break;
   default:
    if(text_in[j]>31)
     text_out[k++]=text_in[j];
    break;
  }
 }
}

void build_main_page(){
 FILE* index;
 index=fopen(POSTS_FILENAME,"w");
 if(index){
  fputs("<?xml version\"1.0\" encoding=\"utf-8\"?>\n",index);
  fputs("<posts>\n</posts>\n",index);
  fclose(index);
 }
 return;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List