diff src/util.c @ 592:7c75d69a1129

[gaim-migrate @ 602] this really cool guy sent a patch to convert %n, %d and %t to things in away messages. i just wish i could remember his name. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 03 Aug 2000 05:35:13 +0000
parents 4bf9c74b9e4d
children 9b0717b4a490
line wrap: on
line diff
--- a/src/util.c	Thu Aug 03 02:05:26 2000 +0000
+++ b/src/util.c	Thu Aug 03 05:35:13 2000 +0000
@@ -837,3 +837,54 @@
 
 }
 
+/* Look for %n, %d, or %t in msg, and replace with the sender's name, date,
+   or time */
+char *away_subs(char *msg, char *name)
+{
+	char *c;
+	static char cpy[BUF_LONG];
+	int cnt=0;
+	time_t t = time(0);
+	struct tm *tme = localtime(&t);
+	char tmp[20];
+
+	cpy[0] = '\0';
+	c = msg;
+	while(*c) {
+		switch(*c) {
+		case '%':
+			if (*(c+1)) {
+				switch (*(c+1)) {
+				case 'n':
+					// append name
+					strcpy (cpy+cnt, name);
+					cnt += strlen(name);
+					c++;
+					break;
+				case 'd':
+					// append date
+					strftime (tmp, 20, "%D", tme);
+					strcpy (cpy+cnt, tmp);
+					cnt += strlen(tmp);
+					c++;
+					break;
+				case 't':
+					// append time
+					strftime (tmp, 20, "%r", tme);
+					strcpy (cpy+cnt, tmp);
+					cnt += strlen(tmp);
+					c++;
+					break;
+				default:
+					cpy[cnt++]=*c;
+				}
+			}
+			break;
+		default:
+			cpy[cnt++]=*c;
+		}
+		c++;
+	}
+	cpy[cnt]='\0';
+	return(cpy);
+}