#include <stdio.h> #include <string.h> #include <stdlib.h> #include <dos.h> #define Bestand "C:\\Documents and Settings\\smessah\\Desktop\\Store.dat" #define NewBron "C:\\Documents and Settings\\smessah\\My Documents\\Tools\\Scan ningTool\\parsed.txt" //C:\Documents and Settings\smessah\Desktop\Store.dat char CurDir[2000]; //storing current directory GLOBAL char Dir[2000]; // original local to copy to global CurDir char *userplcGlb; // global pointer to keep position user char Separator;// global value to add to the printouts so the files are readable by the DB-import int PrintInt;// global bool value indicating if contents must be printed or not. FILE *fp; FILE *np; void arraytrans(char *src, char *dest, int frm, int t2);//prototype int parser(char lijn[]);//prototype void usertrans(char *src, char *dest, char *frm, int t2); //prototype void filetrans(char *src, char *dest, char *frm, int t2); //prototype long filesize(char *src, char *dest, char *frm);//Prototype void directotrans(char *src, char *dest, char *frm); // Prototype char *replace_str(char *str, char *orig, char *rep);// Prototype void replace(char * o_string, char * s_string, char * r_string); #define MAX_L 4096 int main(int argc, char *argv[]) { if (argc != 5) { printf("Error: Not the required amount of arguments."); printf("%i", argc); getchar(); return -1; } /*if (argc == 2) { fp = fopen(argv[1],"r"); np = fopen(NewBron, "w"); printf("Error: Only source %s", fp); getchar(); return -1; } if (argc == 3) { fp = fopen(argv[1], "r"); np = fopen(argv[2], "w"); printf("Error: No Separator %s %s", fp, np); getchar(); return -1; }*/ if (argc == 5) { fp = fopen(argv[1], "r"); np = fopen(argv[2], "w"); Separator = *argv[3]; PrintInt = atoi(argv[4]); printf("Both files & Separator %s %s %c\n", fp, np, Separator); } /*
if(fp!= NULL) { printf("opened file.\n"); } else{ printf("could not open file.\n");} if(np!= NULL) { printf("opened write file.\n"); } else{ printf("could not open write file.\n"); return -1; } getchar(); printf("Give me the separator ';' or '|' : "); scanf("%c",&Separator);*/ if(PrintInt == 1){printf("%c", Separator); getchar(); } fprintf(np,"Opened%c", Separator); fprintf(np,"Day%c", Separator); fprintf(np,"Month%c", Separator); fprintf(np,"Year%c", Separator); fprintf(np,"TimeStampSort%c", Separator); fprintf(np,"Hour%c", Separator); fprintf(np,"Minute%c", Separator); fprintf(np,"Size_Bytes%c", Separator); fprintf(np,"Post\\UserName%c", Separator); fprintf(np,"ParentFolder%c", Separator); fprintf(np,"Filename%c", Separator); fprintf(np,"Full_URL\n"); if(PrintInt == 1){ //Screen Refresh parameter test printf("Opened%c", Separator); printf("Day%c", Separator); printf("Month%c", Separator); printf("Year%c", Separator); printf("TimeStampSort%c", Separator); printf("Hour%c", Separator); printf("Minute%c", Separator); printf("Size_KB%c", Separator); printf("Post\\UserName%c", Separator); printf("ParentFolder%c", Separator); printf("Filename%c", Separator); printf("Full_URL"); getchar(); // No screen refresh means no validation } char line[300]; while(fgets(line,sizeof(line),fp)) {//loop through file parser(line); // printf( "%s \n" , line); }//end off while
fclose(fp); fclose(np); if(PrintInt == 1){getchar();} return 0; } int parser(char lijn[2000]) { char char char char char char char char char char char long CurDate[19]; // date from file Date[5]; // modified Date month[3]; //modified Date day[3]; //modified Day hour[3];// minute[3];// dycopy[3]; //copy day file[200]; //filename *userplc; // position of user indicated by 'POST\\' preset user[13];// size[20];//to get fieldsize flsize; // long integer for filesize
if(!(p = strstr(str, orig))) // Is 'orig' even in 'str'? return str; strncpy(buffer, str, p-str); // Copy characters from 'str' start to 'orig' st$ buffer[p-str] = '\0'; sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig)); return buffer; } /** * The replace function * * Searches all of the occurrences using recursion * and replaces with the given string * @param char * o_string The original string * @param char * s_string The string to search for * @param char * r_string The replace string * @return void The o_string passed is modified */ void replace(char * o_string, char * s_string, char * r_string) { //a buffer variable to do all replace things char buffer[MAX_L]; //to store the pointer returned from strstr char * ch; //first exit condition if(!(ch = strstr(o_string, s_string))) return; //copy all the content to buffer before the first occurrence of the search string strncpy(buffer, o_string, ch-o_string); //prepare the buffer for appending by adding a null to the end of it buffer[ch-o_string] = 0; //append using sprintf function sprintf(buffer+(ch - o_string), "%s%s", r_string, ch + strlen(s_string)); //empty o_string for copying o_string[0] = 0; strcpy(o_string, buffer); //pass recursively to replace other occurrences return replace(o_string, s_string, r_string); } /* char[] clear(char passstr[200], int arg) { int i;//forloop int t; //count spaces t = 0; char res[200]; for(int i = 0; i < sizeof(passstr); i++) { if(passstr[i]== " ") { t++; }