15 Dec, 2012, Igabod wrote in the 1st comment:
Votes: 0
I would like to add a date stamp to the beginning of each reported bug/typo via the commands bug and typo as well as the name of the person who reported it. The code is fairly basic.

void do_bug( CHAR_DATA *ch, char *argument )
{
append_file( ch, BUG_FILE, argument );
send_to_char( "Ok. Thanks.\n\r", ch );
return;
}


How would I make it so the date and only the date (month/day/year) are displayed followed by the name and then the argument?

example:
Quote
12-15-12 (John): I typed who and crashed the mud.
12-15-12 (Bill): I typed who and then the mud died.
12-15-12 (Todd): I think the who command is broken. It crashed the mud.


edit to add:
I suspect I will need to do something with the void append_file function.

void append_file( CHAR_DATA *ch, char *file, char *str )
{
FILE *fp;

if ( IS_NPC(ch) || str[0] == '\0' )
return;

fclose( fpReserve );
if ( ( fp = fopen( file, "a" ) ) == NULL )
{
perror( file );
send_to_char( "Could not open the file!\n\r", ch );
}
else
{
fprintf( fp, "[%5d] %s: %s\n",
ch->in_room ? ch->in_room->vnum : 0, ch->name, str );
fclose( fp );
}

fpReserve = fopen( NULL_FILE, "r" );
return;
}


It appears it already shows the name but not the date stamp. any help would be nice. I know I will have to add a %s but don't know what to define it as on the next line.
15 Dec, 2012, Igabod wrote in the 2nd comment:
Votes: 0
Okay so I added strtime which is defined as ctime (&current_time) but it's not exactly what I want. And it puts a \nr in there before the name and argument. Is there a different version of current_time which only shows date? If not, is there a way I can put the date on the same line as the rest of it?

Quote
Sat Dec 15 07:25:09 2012
Igabod: This is a test of the bug command


but I want

Quote
Dec 15 2012 Igabod: This is a test of the bug command
15 Dec, 2012, Davion wrote in the 3rd comment:
Votes: 0
Take a look at strftime(). It's most likely, exactly what you want.
15 Dec, 2012, Igabod wrote in the 4th comment:
Votes: 0
okay, I looked at that link and it didn't make it clear what I would need to input into my code to get it to display. currently I added the following 2 lines to the top of the function

char *strtime;
strtime = ctime (&current_time);

and they are being used as follows

fprintf( fp, "%s (%s): %s\n", strtime, ch->name, str );
fclose( fp );

how would I need to change that?
15 Dec, 2012, Davion wrote in the 5th comment:
Votes: 0
It functions a lot like snprintf but you provide a timestamp instead of a corresponding argument list. At the bottom there's a couple examples of some formats.

Quote
RFC 2822-compliant date format (with an English locale for %a and %b)
"%a, %d %b %Y %T %z"
RFC 822-compliant date format (with an English locale for %a and %b)
"%a, %d %b %y %T %z"


So something like
char strtime[MSL];
strftime(strtime, MSL, "%a, %d %b %y %T %z", t_time);
15 Dec, 2012, Igabod wrote in the 6th comment:
Votes: 0
{
FILE *fp;
char strtime[MSL];
strftime(strtime, MSL, "%x", t_time);


if ( IS_NPC(ch) || str[0] == '\0' )
return;

fclose( fpReserve );
if ( ( fp = fopen( file, "a" ) ) == NULL )
{
perror( file );
send_to_char( "Could not open the file!\n\r", ch );
}
else
{
fprintf( fp, "%s (%s): %s\n", strftime, ch->name, str );
fclose( fp );
}

fpReserve = fopen( NULL_FILE, "r" );
return;
}


I used the %x cause it is exactly the format I wanted and shorter. Would this work or do I need to make further changes?
15 Dec, 2012, Davion wrote in the 7th comment:
Votes: 0
fprintf( fp, "%s (%s): %s\n", strftime, ch->name, str );
fclose( fp );


This will not work because you're using the function name. You'll want that to be strtime. In hindsight, I probably shouldn't have used similar names :D
15 Dec, 2012, Igabod wrote in the 8th comment:
Votes: 0
Ok so the only correction is strtime not strftime right? I will do that after I get off work. Thanks.
15 Dec, 2012, Sharmair wrote in the 9th comment:
Votes: 0
Igabod said:
Ok so the only correction is strtime not strftime right? I will do that after I get off work. Thanks.

From the info in the posts here so far, I would say no, in fact I would not be surprised if it either does not compile or crashes.
The main problem I see would depend on what exactly t_time is. You do not show what it is defined as (if it even is), and use
it as two different things in different posts. In post 4 you use it as a time_t**, then later Davion and then you use it as a
struct tm* (I almost think it is a mistype of current_time from what you say in post 2). Assuming you start with a time_t
current_time that a lot of MUDs have set as a global, and going for how you wanted it to look on your first post, something
like this at the top of the function should work:
char strtime[MSL];
struct tm* ptmst = localtime(& current_time);

strftime(strtime, MSL, "%m-%d-%y", ptmst);

If you want the longer date format you later said you wanted, just change the format string of the strftime call. Also, if
you just wanted the numbers, you could forget strftime and just use the fields of the struct tm directly in your fprintf
(ptmst->tm_mday, ptmst->tm_mon and ptmst-> tm_year in this case) with proper formatting.

edit: noticed after posting that my &current_time was changed to *t_time, so it seems the t_time confusion started not
as a mistype, but with mudbytes messing with the input. I added a space between the & and current_time.
16 Dec, 2012, Igabod wrote in the 10th comment:
Votes: 0
It works but it spits out this warning.
iggystuff.c:241:5: warning: passing argument 1 of strftime from incompatible pointer type
/usr/include/time.h:56:11: note: expected char * but argument is of type char **
iggystuff.c:252:2: warning: format %s expects type char *, but argument 3 has type char **
iggystuff.c:252:2: warning: format %s expects type char *, but argument 3 has type char **

Here is the code I have.
void append_file( CHAR_DATA *ch, char *file, char *str )
{
FILE *fp;
char *strtime[MAX_STRING_LENGTH];
struct tm* ptmst = localtime(&current_time);


if ( IS_NPC(ch) || str[0] == '\0' )
return;

strftime(strtime, MAX_STRING_LENGTH, "%m-%d-%y", ptmst);

fclose( fpReserve );
if ( ( fp = fopen( file, "a" ) ) == NULL )
{
perror( file );
send_to_char( "Could not open the file!\n\r", ch );
}
else
{
fprintf( fp, "%s (%s): %s\n", strtime, ch->name, str );
fclose( fp );
}

fpReserve = fopen( NULL_FILE, "r" );
return;
}
16 Dec, 2012, Hades_Kane wrote in the 11th comment:
Votes: 0
Something completely different to consider, which is how we handle it now…

I created a new immortal-only note board called Bugs/Typo and anytime someone uses the bugs/typo command, it logs to the board instead, including the person who sent it, and as with any other notes, date, time, etc.

Then when someone fixes a bug or a typo, they just simply delete the note. This works MUCH better than having to go into the shell to check a text file, which was honestly only done once in a blue moon. With it accessible to multiple immortals, bugs and typos are addressed MUCH faster that way. Players tend to respond pretty well to seeing such a quick response to their bug/typo reports too, which seems to encourage them.
16 Dec, 2012, Igabod wrote in the 12th comment:
Votes: 0
I was actually planning on having a command to call up the bugs.txt. Just type viewbugs and it shows the list. I would probably need to make it have arguments too like viewbugs 1 for the first page viewbugs 2 for the 2nd etc. I just haven't been able to find any examples of existing code that do something similar so I don't have a clue how to do it. I am also going to do the same with changes. I already made the command to add text to changes.txt. Just need a command to call up that file now.

Any pointers in this direction would be awesome.
16 Dec, 2012, Sharmair wrote in the 13th comment:
Votes: 0
Igabod said:
It works but it spits out this warning.
iggystuff.c:241:5: warning: passing argument 1 of strftime from incompatible pointer type
/usr/include/time.h:56:11: note: expected char * but argument is of type char **
iggystuff.c:252:2: warning: format %s expects type char *, but argument 3 has type char **
iggystuff.c:252:2: warning: format %s expects type char *, but argument 3 has type char **

Here is the code I have.
void append_file( CHAR_DATA *ch, char *file, char *str )
{
FILE *fp;
char *strtime[MAX_STRING_LENGTH];

I think you want an array of char there, not an array of char* - take out the *.
16 Dec, 2012, Igabod wrote in the 14th comment:
Votes: 0
That fixed it, thanks Sharmair.
17 Dec, 2012, Igabod wrote in the 15th comment:
Votes: 0
I'm still looking for a way to access the bugfile via a command in the game as well as a changes.txt file. I am thinking that I could alter the help command and have it pull information from changes.txt rather than help.are and edit the append_file command to group the entries into chunks of 25 or so entries per "page". So if I type "changes 1" it brings up the first 25 entries into changes.txt and if I type "viewbugs 3" it brings up the 3rd 25 entries on bugs.txt. This is all very easy to visualize how it would work but I just don't have the experience in doing this.

It seemed like such a simple idea until I got halfway through. Somebody please help. Even just a simple explanation of how the help command pulls info from the help.are file would be helpful.
17 Dec, 2012, Tijer wrote in the 16th comment:
Votes: 0
i have some code on my mud that logs missing helpfile requests using append file

void do_helplist (CHAR_DATA * ch, char *argument)
{
char *buf;
char buf2[MAX_STRING_LENGTH];
FILE *fp;
char clear;

if ((fp = fopen (HELP_LIST, "r")) == NULL)
return;

send_to_char ("\n\r#oHelp File requests:#n\n\r\n\r", ch);

while (getc (fp) == ';
FILE *fp;
char clear;

if ((fp = fopen (HELP_LIST, "r")) == NULL)
return;

send_to_char ("\n\r#oHelp File requests:#n\n\r\n\r", ch);

while (getc (fp) == '[')
{
buf = fread_string (fp);
sprintf (buf2, "[%s\n\r", buf);
send_to_char (buf2, ch);
clear = getc (fp);
}

fclose (fp);
return;
}
[/code]

Append file needs some minor modifications to get this to work with this

[code]
void append_file( CHAR_DATA *ch, char *file, char *str )
{
FILE *fp;
char *strtime;
if ( IS_NPC(ch) || str[0] == '\0' )
return;

if ( ( fp = fopen( file, "a" ) ) == NULL )
{
perror( file );
send_to_char( "Could not open the file!\n\r", ch );
}
else
{
strtime = ctime( &current_time );
strtime[strlen(strtime)-1] = '\0';
fprintf( fp, "[%s] %s: %s~\n",
new_date(current_time), ch->name, str );
fflush( fp );
fclose( fp );
}

return;
}
[/code]

my new_date function just modifies the way the date is shown!! (so you probably can use what you were using… previously)

Hope this helps, only modifications it requires is some kind of paging code…. :)
17 Dec, 2012, Igabod wrote in the 17th comment:
Votes: 0
I added the first bit of code and just changed some words from help to change to test it with my change.txt file. Everything compiled nicely but when I enter the command it only displays the message I put in place of "Help file requests:". Is this because the information in changes.txt needs to be in a certain format to be displayed properly?
17 Dec, 2012, Sharmair wrote in the 18th comment:
Votes: 0
Here is some code based on my SMAUG code that does have a command to list a number of files
in game. This is based on stock SMAUG code by Thoric modified by me for my code, then pulled
out and made into a function for just the bug file and removing some things you might not have.
void do_bshow(CHAR_DATA* ch, char* argument){
FILE* fp;
char buf[MAX_STRING_LENGTH];
int c;
int num = 0;

fclose(fpReserve);
if((fp = fopen(PBUG_FILE, "r")) != NULL){// Filename and path of bugs file from current dir
while(!feof(fp)){
while((c = fgetc(fp)) != EOF && (buf[num] = (char)c) != '\n'
&& buf[num] != '\r' && num < (MAX_STRING_LENGTH-3))
++num;
c = fgetc(fp);
if((c != '\n' && c != '\r') || c == buf[num])
ungetc(c, fp);
buf[num++] = '\r';
buf[num++] = '\n';
buf[num ] = '\0';
send_to_pager(buf, ch);// Use send_to_char if you don't have pager code
num = 0;
}
fclose(fp);
}
fpReserve = fopen(NULL_FILE, "r");
}
17 Dec, 2012, Tijer wrote in the 19th comment:
Votes: 0
you need to make a command that actually uses append file… it wont actually do anything untill you create it, it should however still show stuff that is in the bugs file.. ideas file etc etc….
17 Dec, 2012, Igabod wrote in the 20th comment:
Votes: 0
I made a command called addchange which uses append_changes which is a rewrite of the append_file command. But that code you gave me doesn't show anything that is in the file.
0.0/25