home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume36 / remind / patch04c < prev    next >
Encoding:
Text File  |  1993-03-06  |  14.0 KB  |  427 lines

  1. Newsgroups: comp.sources.misc
  2. From: <dfs@doe.carleton.ca> (David F. Skoll)
  3. Subject: v36i003:  remind - A replacement for calendar, Patch04c/3
  4. Message-ID: <1993Mar8.040403.21176@sparky.imd.sterling.com>
  5. X-Md4-Signature: 4db955a78f5a214dae23847369452b30
  6. Date: Mon, 8 Mar 1993 04:04:03 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: <dfs@doe.carleton.ca> (David F. Skoll)
  10. Posting-number: Volume 36, Issue 3
  11. Archive-name: remind/patch04c
  12. Environment: UNIX, MS-DOS
  13. Patch-To: remind: Volume 33, Issue 58-69
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # Contents:  finnish.h sort.c
  20. # Wrapped by kent@sparky on Sun Mar  7 21:51:02 1993
  21. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 3 (of 3)."'
  24. if test -f 'finnish.h' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'finnish.h'\"
  26. else
  27.   echo shar: Extracting \"'finnish.h'\" \(5690 characters\)
  28.   sed "s/^X//" >'finnish.h' <<'END_OF_FILE'
  29. X/***************************************************************/
  30. X/*                                                             */
  31. X/*  FINNISH.H                                                  */
  32. X/*                                                             */
  33. X/*  Support for the Finnish language.                          */
  34. X/*                                                             */
  35. X/*  Author: Mikko Silvonen (Mikko.Silvonen@Helsinki.FI)        */
  36. X/*                                                             */
  37. X/*  This file is part of REMIND.                               */
  38. X/*  Copyright (C) 1992, 1993 by David F. Skoll.                */
  39. X/*                                                             */
  40. X/***************************************************************/
  41. X
  42. X/* All Finnish words in this file are in "7-bit Finnish ASCII";
  43. X   they can be converted to other character sets if needed. */
  44. X   
  45. X/* The very first define in a language support file must be L_LANGNAME: */
  46. X#define L_LANGNAME "Finnish"
  47. X
  48. X/* Day names */
  49. X#define L_SUNDAY "sunnuntai"
  50. X#define L_MONDAY "maanantai"
  51. X#define L_TUESDAY "tiistai"
  52. X#define L_WEDNESDAY "keskiviikko"
  53. X#define L_THURSDAY "torstai"
  54. X#define L_FRIDAY "perjantai"
  55. X#define L_SATURDAY "lauantai"
  56. X
  57. X/* Day initials - first letter only */
  58. X#define L_DAYINIT "SMTKTPL"
  59. X
  60. X/* Month names */
  61. X#define L_JAN "tammikuu"
  62. X#define L_FEB "helmikuu"
  63. X#define L_MAR "maaliskuu"
  64. X#define L_APR "huhtikuu"
  65. X#define L_MAY "toukokuu"
  66. X#define L_JUN "kes{kuu"
  67. X#define L_JUL "hein{kuu"
  68. X#define L_AUG "elokuu"
  69. X#define L_SEP "syyskuu"
  70. X#define L_OCT "lokakuu"
  71. X#define L_NOV "marraskuu"
  72. X#define L_DEC "joulukuu"
  73. X
  74. X/* Today and tomorrow */
  75. X#define L_TODAY "t{n{{n"
  76. X#define L_TOMORROW "huomenna"
  77. X
  78. X/* The default banner */
  79. X#define L_BANNER "Viestit %wna, %d. %mta %y%o:"
  80. X
  81. X/* "am" and "pm" */
  82. X#define L_AM "ap"
  83. X#define L_PM "ip"
  84. X
  85. X/*** The following are only used in dosubst.c ***/
  86. X#ifdef L_IN_DOSUBST
  87. X
  88. X/* Ago and from now */
  89. X#define L_AGO "sitten"
  90. X#define L_FROMNOW "kuluttua"
  91. X
  92. X/* "in %d days' time" */
  93. X#define L_INXDAYS "%d p{iv{n kuluttua"
  94. X
  95. X/* "on" as in "on date...", but in Finnish it is a case ending;
  96. X   L_PARTIT is the partitive ending appended to -kuu and -tai */
  97. X#define L_ON "na"
  98. X#define L_PARTIT "ta"
  99. X
  100. X/* Pluralizing - this is a problem for many languages and may require
  101. X   a more drastic fix */
  102. X/* The partitive ending of "day" */
  103. X#define L_PLURAL "{"
  104. X
  105. X/* Minutes, hours, at, etc */
  106. X#define L_NOW "nyt"
  107. X#define L_AT "klo"
  108. X#define L_MINUTE "minuutti"
  109. X#define L_HOUR "tunti"
  110. X#define L_IS "on"
  111. X#define L_WAS "oli"
  112. X#define L_AND "ja"
  113. X
  114. X/* What to add to make "hour" plural (or actually partitive) */
  115. X#define L_HPLU "a"  
  116. X/* What to add to make "minute" plural (or actually partitive) */
  117. X#define L_MPLU "a"
  118. X
  119. X/* Genitive form of "hour" */
  120. X#define L_HGEN "tunnin"
  121. X/* Genitive form of "minute" */
  122. X#define L_MGEN "minuutin"
  123. X
  124. X/* Define any overrides here, such as L_ORDINAL_OVERRIDE, L_A_OVER, etc.
  125. X   See the file dosubst.c for more info. */
  126. X
  127. X#define L_ORDINAL_OVERRIDE switch(d) { \
  128. X                               case 1:  plu = ":sen{"; break; \
  129. X                               case 2:  plu = ":sena"; break; \
  130. X                               default: \
  131. X                                   switch(d%10) { \
  132. X                                       case 2: \
  133. X                                       case 3: \
  134. X                                       case 6: \
  135. X                                       case 8:  plu = ":ntena"; break; \
  136. X                                       default: plu = ":nten{"; break; \
  137. X                                   } \
  138. X                           }
  139. X#define L_A_OVER sprintf(s, "%s%s, %d. %s%s %d", DayName[jul%7], L_ON, d, \
  140. X                         MonthName[m], L_PARTIT, y);
  141. X#define L_C_OVER sprintf(s, "%s%s", DayName[jul%7], L_ON);
  142. X#define L_E_OVER sprintf(s, "%02d%c%02d%c%04d", d, DATESEP, m+1, DATESEP, \
  143. X                         y);
  144. X#define L_F_OVER sprintf(s, "%02d%c%02d%c%04d", m+1, DATESEP, d, DATESEP, y);
  145. X#define L_G_OVER sprintf(s, "%s%s, %d. %s%s", DayName[jul%7], L_ON, d, \
  146. X                         MonthName[m], L_PARTIT);
  147. X#define L_H_OVER sprintf(s, "%02d%c%02d", d, DATESEP, m+1);
  148. X#define L_I_OVER sprintf(s, "%02d%c%02d", m+1, DATESEP, d);
  149. X#define L_J_OVER sprintf(s, "%s%s, %sn %d%s %d", DayName[jul%7], L_ON, \
  150. X                         MonthName[m], d, plu, y);
  151. X#define L_K_OVER sprintf(s, "%s%s, %sn %d%s", DayName[jul%7], L_ON, \
  152. X               MonthName[m], d, plu);
  153. X#define L_L_OVER sprintf(s, "%04d%c%02d%c%02d", y, DATESEP, m+1, DATESEP, d);
  154. X#define L_Q_OVER sprintf(s, "n");
  155. X#define L_U_OVER sprintf(s, "%s%s, %d%s %s%s %d", DayName[jul%7], L_ON, \
  156. X                            d, plu, MonthName[m], L_PARTIT, y);
  157. X#define L_V_OVER sprintf(s, "%s%s, %d%s %s%s", DayName[jul%7], L_ON, d, \
  158. X                         plu, MonthName[m], L_PARTIT);
  159. X#define L_1_OVER if (tdiff == 0) \
  160. X                     sprintf(s, L_NOW); \
  161. X                 else { \
  162. X                     if (hdiff != 0) { \
  163. X                         if (tdiff < 0) \
  164. X                             sprintf(s, "%d %s%s ", hdiff, L_HOUR, hplu); \
  165. X                         else \
  166. X                             sprintf(s, "%d %s ", hdiff, L_HGEN); \
  167. X                         s += strlen(s); \
  168. X                     } \
  169. X                     if (mdiff != 0) { \
  170. X                         if (tdiff < 0) \
  171. X                             sprintf(s, "%d %s%s ", mdiff, L_MINUTE, \
  172. X                                     mplu); \
  173. X                         else \
  174. X                             sprintf(s, "%d %s ", mdiff, L_MGEN); \
  175. X                         s += strlen(s); \
  176. X                     } \
  177. X                     sprintf(s, when); \
  178. X                 }
  179. X#endif /* L_IN_DOSUBST */
  180. END_OF_FILE
  181.   if test 5690 -ne `wc -c <'finnish.h'`; then
  182.     echo shar: \"'finnish.h'\" unpacked with wrong size!
  183.   fi
  184.   # end of 'finnish.h'
  185. fi
  186. if test -f 'sort.c' -a "${1}" != "-c" ; then 
  187.   echo shar: Will not clobber existing file \"'sort.c'\"
  188. else
  189.   echo shar: Extracting \"'sort.c'\" \(6263 characters\)
  190.   sed "s/^X//" >'sort.c' <<'END_OF_FILE'
  191. X/***************************************************************/
  192. X/*                                                             */
  193. X/*  SORT.C                                                     */
  194. X/*                                                             */
  195. X/*  Routines for sorting reminders by trigger date             */
  196. X/*                                                             */
  197. X/*  This file is part of REMIND.                               */
  198. X/*  Copyright (C) 1992, 1993 by David F. Skoll.                */
  199. X/*                                                             */
  200. X/***************************************************************/
  201. X#include "config.h"
  202. X
  203. X#ifdef HAVE_STDLIB_H
  204. X#include <stdlib.h>
  205. X#endif
  206. X
  207. X#ifdef HAVE_MALLOC_H
  208. X#include <malloc.h>
  209. X#endif
  210. X
  211. X#include <stdio.h>
  212. X#include <string.h>
  213. X#include "types.h"
  214. X#include "protos.h"
  215. X#include "expr.h"
  216. X#include "globals.h"
  217. X#include "err.h"
  218. X
  219. X/* The structure of a sorted entry */
  220. Xtypedef struct sortrem {
  221. X   struct sortrem *next;
  222. X   char *text;
  223. X   int trigdate;
  224. X   int trigtime;
  225. X   int typ;
  226. X} Sortrem;
  227. X
  228. X/* The sorted reminder queue */
  229. Xstatic Sortrem *SortedQueue = (Sortrem *) NULL;
  230. X
  231. XPRIVATE Sortrem *MakeSortRem ARGS ((int jul, int tim, char *body, int typ));
  232. XPRIVATE void IssueSortBanner ARGS ((int jul));
  233. X
  234. X/***************************************************************/
  235. X/*                                                             */
  236. X/*  MakeSortRem                                                */
  237. X/*                                                             */
  238. X/*  Create a new Sortrem entry - return NULL on failure.       */
  239. X/*                                                             */
  240. X/***************************************************************/
  241. X#ifdef HAVE_PROTOS
  242. XPRIVATE Sortrem *MakeSortRem(int jul, int tim, char *body, int typ)
  243. X#else
  244. Xstatic Sortrem *MakeSortRem(jul, tim, body, typ)
  245. Xint jul, tim;
  246. Xchar *body;
  247. Xint typ;
  248. X#endif
  249. X{
  250. X   Sortrem *new = NEW(Sortrem);
  251. X   if (!new) return NULL;
  252. X
  253. X   new->text = StrDup(body);
  254. X   if (!new->text) {
  255. X      free(new);
  256. X      return NULL;
  257. X   }
  258. X  
  259. X   new->trigdate = jul;
  260. X   new->trigtime = tim;
  261. X   new->typ = typ;
  262. X   new->next = NULL;
  263. X   return new;
  264. X}
  265. X
  266. X/***************************************************************/
  267. X/*                                                             */
  268. X/*  InsertIntoSortBuffer                                       */
  269. X/*                                                             */
  270. X/*  Insert a reminder into the sort buffer                     */
  271. X/*                                                             */
  272. X/***************************************************************/
  273. X#ifdef HAVE_PROTOS
  274. XPUBLIC int InsertIntoSortBuffer(int jul, int tim, char *body, int typ)
  275. X#else
  276. Xint InsertIntoSortBuffer(jul, tim, body, typ)
  277. Xint jul;
  278. Xint tim;
  279. Xchar *body;
  280. Xint typ;
  281. X#endif
  282. X{
  283. X   Sortrem *new = MakeSortRem(jul, tim, body, typ);
  284. X   Sortrem *cur = SortedQueue, *prev = NULL;
  285. X   int ShouldGoAfter;
  286. X
  287. X   if (!new) {
  288. X      Eprint("Out of memory for sorting.");
  289. X      IssueSortedReminders();
  290. X      SortByDate = 0;
  291. X      SortByTime = 0;
  292. X      return E_NO_MEM;
  293. X   }
  294. X
  295. X   /* Find the correct place in the sorted list */
  296. X   if (!SortedQueue) {
  297. X      SortedQueue = new;
  298. X      return OK;
  299. X   }
  300. X   while (cur) {
  301. X      if (cur->trigdate == new->trigdate) {
  302. X         ShouldGoAfter =
  303. X        (SortByTime == SORT_ASCEND) ?
  304. X           (new->trigtime >= cur->trigtime) :
  305. X           ((new->trigtime == NO_TIME) || (new->trigtime <= cur->trigtime));
  306. X      } else {
  307. X         ShouldGoAfter =
  308. X        (SortByDate == SORT_ASCEND) ?
  309. X           (new->trigdate >= cur->trigdate) :
  310. X           (new->trigdate <= cur->trigdate);
  311. X      }
  312. X
  313. X      if (ShouldGoAfter) {
  314. X         prev = cur;
  315. X     cur = cur->next;
  316. X      } else {
  317. X         if (prev) {
  318. X        prev->next = new;
  319. X        new->next = cur;
  320. X     } else {
  321. X        SortedQueue = new;
  322. X        new->next = cur;
  323. X     }
  324. X     return OK;
  325. X      }
  326. X      
  327. X   }
  328. X   prev->next = new;
  329. X   new->next = cur;  /* For safety - actually redundant */
  330. X   return OK;
  331. X}
  332. X
  333. X   
  334. X/***************************************************************/
  335. X/*                                                             */
  336. X/*  IssueSortedReminders                                       */
  337. X/*                                                             */
  338. X/*  Issue all of the sorted reminders and free memory.         */
  339. X/*                                                             */
  340. X/***************************************************************/
  341. X#ifdef HAVE_PROTOS
  342. XPUBLIC void IssueSortedReminders(void)
  343. X#else
  344. Xvoid IssueSortedReminders()
  345. X#endif
  346. X{
  347. X   Sortrem *cur = SortedQueue;
  348. X   Sortrem *next;
  349. X   int olddate = NO_DATE;
  350. X
  351. X   while (cur) {
  352. X      next = cur->next;
  353. X      if (cur->typ == MSG_TYPE) {
  354. X    if (!MsgCommand) {
  355. X            if (cur->trigdate != olddate) {
  356. X               IssueSortBanner(cur->trigdate);
  357. X           olddate = cur->trigdate;
  358. X            }
  359. X            printf("%s\n", cur->text);
  360. X         } else {
  361. X            char buf[LINELEN+TOKSIZE];
  362. X            sprintf(buf, MsgCommand, cur->text);
  363. X        system(buf);
  364. X         }
  365. X      } else { /* Must be RUN_TYPE */
  366. X         system(cur->text);
  367. X      }
  368. X      free(cur->text);
  369. X      free(cur);
  370. X      cur = next;
  371. X   }
  372. X}
  373. X/***************************************************************/
  374. X/*                                                             */
  375. X/*  IssueSortBanner                                            */
  376. X/*                                                             */
  377. X/*  Issue a daily banner if the function sortbanner() is       */
  378. X/*  defined to take one argument.                              */
  379. X/*                                                             */
  380. X/***************************************************************/
  381. X#ifdef HAVE_PROTOS
  382. XPRIVATE void IssueSortBanner(int jul)
  383. X#else
  384. Xstatic void IssueSortBanner(jul)
  385. Xint jul;
  386. X#endif
  387. X{
  388. X   char BanExpr[25];
  389. X   int y, m, d;
  390. X   Value v;
  391. X   char *s = BanExpr;
  392. X
  393. X   if (UserFuncExists("sortbanner") != 1) return;
  394. X
  395. X   FromJulian(jul, &y, &m, &d);
  396. X   sprintf(BanExpr, "sortbanner('%04d/%02d/%02d')", y, m+1, d);   
  397. X   y = EvalExpr(&s, &v);
  398. X   if (y) return;
  399. X   if (DoCoerce(STR_TYPE, &v)) return;
  400. X   if (!DoSubstFromString(v.v.str, SubstBuffer, jul, NO_TIME))
  401. X      if (*SubstBuffer) printf("%s\n", SubstBuffer);
  402. X   DestroyValue(&v);
  403. X}
  404. END_OF_FILE
  405.   if test 6263 -ne `wc -c <'sort.c'`; then
  406.     echo shar: \"'sort.c'\" unpacked with wrong size!
  407.   fi
  408.   # end of 'sort.c'
  409. fi
  410. echo shar: End of archive 3 \(of 3\).
  411. cp /dev/null ark3isdone
  412. MISSING=""
  413. for I in 1 2 3 ; do
  414.     if test ! -f ark${I}isdone ; then
  415.     MISSING="${MISSING} ${I}"
  416.     fi
  417. done
  418. if test "${MISSING}" = "" ; then
  419.     echo You have unpacked all 3 archives.
  420.     rm -f ark[1-9]isdone
  421. else
  422.     echo You still must unpack the following archives:
  423.     echo "        " ${MISSING}
  424. fi
  425. exit 0
  426. exit 0 # Just in case...
  427.