This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Geek2France/master
The new online-resume mode resumes from where it was stopped
- Loading branch information
Showing
5 changed files
with
240 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "fw1-cursor.h" | ||
|
||
int read_fw1_cursorfile () { | ||
rewind (cursorstream); | ||
fgets (cursorline, (POSITION_MAX_SIZE + 1), cursorstream); | ||
|
||
return atoi (cursorline); | ||
} | ||
|
||
/* Write next log position | ||
* return number of characters written | ||
*/ | ||
int write_fw1_cursorfile (const char *message, const char separator) { | ||
char position[POSITION_MAX_SIZE]; | ||
int i, j = 0; | ||
|
||
rewind (cursorstream); | ||
|
||
// Extract cuurent position from message | ||
for (i=4; i<strlen (message); i++) | ||
{ | ||
if ((char)message[i] != separator) | ||
{ | ||
position[j] = message[i]; | ||
j++; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return fprintf (cursorstream, "%0" TOSTRING(POSITION_MAX_SIZE) "d\n", atoi (position)+1); | ||
} | ||
|
||
char* get_fw1_cursorname(const char *LogfileName) { | ||
char *cursorname = | ||
(char *) malloc (strlen (LogfileName) + 7); | ||
if (cursorname == NULL) | ||
{ | ||
fprintf (stderr, "ERROR: Out of memory\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
strcpy (cursorname, LogfileName); | ||
strcat (cursorname, ".cursor"); | ||
|
||
return cursorname; | ||
} | ||
|
||
void open_fw1_cursorfile (const char *LogfileName) { | ||
char *cursorname = get_fw1_cursorname (LogfileName); | ||
|
||
// Open the file in "a" mode first to create it if it doesn't exist yet | ||
cursorstream = fopen (cursorname,"a"); | ||
if (cursorstream == NULL) | ||
{ | ||
fprintf (stderr, "Error while opening the file %s in a mode.\n", cursorname); | ||
free (cursorname); | ||
exit(EXIT_FAILURE); | ||
} | ||
fclose (cursorstream); | ||
|
||
// Open the file in "a" mode first to create it if it doesn't exist yet | ||
cursorstream = fopen (cursorname,"r+"); | ||
if (cursorstream == NULL) | ||
{ | ||
fprintf (stderr, "Error while opening the file %s in r+ mode.\n", cursorname); | ||
free (cursorname); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
free (cursorname); | ||
} | ||
|
||
void close_fw1_cursorfile() { | ||
fclose (cursorstream); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef FW1CURSOR_H | ||
#define FW1CURSOR_H | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define STRINGIFY(x) #x | ||
#define TOSTRING(x) STRINGIFY(x) | ||
#define POSITION_MAX_SIZE 32 | ||
|
||
FILE *cursorstream; | ||
char cursorline[POSITION_MAX_SIZE + 1]; | ||
|
||
int read_fw1_cursorfile (); // Return next log position from cursor file | ||
int write_fw1_cursorfile (const char *message, const char separator); // Deduce next log position from current message | ||
char* get_fw1_cursorname (const char *LogfileName); // Give cursor name associated with log file | ||
void open_fw1_cursorfile (const char *LogfileName); // Initialize cursorstream file handler | ||
void close_fw1_cursorfile (); // Close cursorstream file handler | ||
|
||
#endif |
Oops, something went wrong.