home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / Converters / DLGGUIDE232.lha / DLGGuide.c next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  20.1 KB  |  640 lines

  1. #define DONGROUT "$VER: DLGGuide  by Don Grout  v2.32  03-May-94"
  2. // converts DLG's BBS message file into an AmigaGuide series of files
  3.  
  4. #define DLGGUIDE   "DLGMsgs.Guide"
  5. #define NEWMSGAREA "Message Area ["
  6. #define ENDMSGAREA ']'
  7. #define NEWSUBJECT "[From    ] "
  8. #define SUBJECT    "[Subject ]"
  9. #define SUBJECTNUM 4
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <time.h>
  15. #ifndef __MSDOS__
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/datetime.h>
  19. #include <workbench/startup.h>
  20. #include <workbench/workbench.h>
  21.  
  22. #include <clib/exec_protos.h>
  23. #include <clib/dos_protos.h>
  24. #include <clib/icon_protos.h>
  25. #endif
  26.  
  27. #define TRUE  1
  28. #define FALSE 0
  29.  
  30. #define AMIGAGUIDEICON 518
  31.  
  32. int AmigaGuideIcon[AMIGAGUIDEICON]= {
  33. 227, 16,  0,  1,  0,  0,  0,  0,  0, 47,  0, 16,  0, 54,  0, 23,  0,  4,  0,
  34.   1,  0,  1,  0, 32,203,136,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  35.   0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  4, 50,  0, 32,207,240,  0, 32,203,
  36.  72,  0,  0,  0, 29,  0,  0,  0,  5,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  37.  16,  0,  0,  0,  0,  0,  0, 54,  0, 22,  0,  2,  0,  1,138,248,  3,  0,  0,
  38.   0,  0,  0,  0,  0,  0,  0,  0,  0,  4,  0,  0,  0,  0,  0,  0,  0, 12,  0,
  39.   0,  0,  0,  0,  0,  0, 12,  0,  7,255,255,255,255,224, 12,  0,  4,  0,  0,
  40.   0,  0, 48, 12,  0,  4,171,250,  0,  0, 40, 12,  0,  4,  0,  0,  0,  0, 36,
  41.  12,  0,  4,191,234,170,170,162, 12,  0,  4,  0,  0,  0,  0, 63, 12,  0,  4,
  42. 170,170,170,170,168,140,  0,  4,  0,  0,  0,  0,  0,140,  0,  4,170,171,254,
  43. 170,168,140,  0,  4,  0,  0,  0,  0,  0,140,  0,  4,170,170,170,170,168,140,
  44.   0,  4,  0,  0,  0,  0,  0,140,  0,  4,191,234,170,254,168,140,  0,  4,  0,
  45.   0,  0,  0,  0,140,  0,  4,  0,  0,  0,  0,  0,140,  0,  7,255,255,255,255,
  46. 255,140,  0,  0,  0,  0,  0,  0,  0, 12,  0,  0,  0,  0,  0,  0,  0, 12,  0,
  47. 127,255,255,255,255,255,252,  0,255,255,255,255,255,255,248,  0,213, 85, 85,
  48.  85, 85, 85, 80,  0,213, 85, 85, 85, 85, 85, 80,  0,208,  0,  0,  0,  0, 21,
  49.  80,  0,211,255,255,255,255,197, 80,  0,211, 85,245,255,255,213, 80,  0,211,
  50. 255,255,255,255,217, 80,  0,211, 95,213, 85, 85, 93, 80,  0,211,255,255,255,
  51. 255,192, 80,  0,211, 85, 85, 85, 85, 87, 80,  0,211,255,255,255,255,255, 80,
  52.   0,211, 85, 85,253, 85, 87, 80,  0,211,255,255,255,255,255, 80,  0,211, 85,
  53.  85, 85, 85, 87, 80,  0,211,255,255,255,255,255, 80,  0,211, 95,213, 85,125,
  54.  87, 80,  0,211,255,255,255,255,255, 80,  0,211,255,255,255,255,255, 80,  0,
  55. 208,  0,  0,  0,  0,  0, 80,  0,213, 85, 85, 85, 85, 85, 80,  0,213, 85, 85,
  56.  85, 85, 85, 80,  0,128,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 25, 83, 89,
  57.  83, 58, 85,116,105,108,105,116,105,101,115, 47, 65,109,105,103, 97, 71,117,
  58. 105,100,101,  0,  0,  0,  0,  8,  0,  0,  0, 31, 70, 73, 76, 69, 84, 89, 80,
  59.  69, 61, 84, 69, 88, 84,124, 65, 83, 67, 73, 73,124, 65, 77, 73, 71, 65, 71,
  60.  85, 73, 68, 69,  0
  61. };
  62.  
  63. FILE *TxtOut, *InputFile, *OutputFile, *GuideFile, *IndexFile;
  64. unsigned char SubjectString[SUBJECTNUM+2][255], MessageArea[255];
  65. unsigned char FileArg[255], PathArg[255], FileDate[20];
  66. unsigned char MsgFileName[255], IndexFileName[255];
  67. char *Flag;
  68. int SubjectCount, PathFlag;
  69.  
  70. #ifndef __MSDOS__
  71. unsigned char WindowArg[255];
  72. #endif
  73.  
  74. struct {int Num; int Skip; char Data[80];} MsgAreaList[99];
  75. int MsgAreaSize, MsgAreaNum;
  76.  
  77. // Function Declaration *****************************************************
  78.  
  79. char *GetFileName(char *);
  80. void master(FILE *);
  81. void toc(FILE *);
  82. void ver(FILE *);
  83. void AddIndex(int,char *,char *);
  84. void LoadMsgArea(char []);
  85. int GetMsgArea(char []);
  86. int IsSkip(int);
  87. void SkipParagraph(FILE *,FILE *);
  88. int SearchAndReplace(char *,char [],char []);
  89. char *WordMonth(int);
  90. void CleanExit(char *);
  91.  
  92. int main(int argc,char *argv[]) // *******************************************
  93. {
  94. char *Pointer;
  95. unsigned char FileName[255], Line[255], xS[255];
  96. int xI;
  97. #ifdef DOS_DATETIME_H
  98. char Date[80]="", Time[80]="";
  99. struct FileLock *FLock;
  100. struct FileInfoBlock *FIBlock;
  101. struct DateTime *DTime;
  102. #else
  103. struct tm *TimePointer;
  104. time_t SecsNow;
  105. #endif
  106.  
  107. // Create an Argument String
  108. strcpy(Line," ");
  109.  
  110. #ifndef __MSDOS__
  111. if (!argc) {
  112.  struct WBStartup  *WBenchMsg;
  113.  struct WBArg      *WBenchArg;
  114.  struct DiskObject *DskObj;
  115.  struct Library    *IconBase;
  116.  WBenchMsg=(struct WBStartup *)argv;
  117.  WBenchArg=WBenchMsg->sm_ArgList;
  118.  IconBase=OpenLibrary("icon.library",33);
  119.  if (IconBase) {
  120.   DskObj=GetDiskObject(WBenchArg->wa_Name);
  121.   if (DskObj) {
  122.    xI=0;
  123.    while (DskObj->do_ToolTypes[xI]) {
  124.     strcat(Line,DskObj->do_ToolTypes[xI]); strcat(Line," ");
  125.     xI++;
  126.     }
  127.    FreeDiskObject(DskObj);
  128.    }
  129.   CloseLibrary(IconBase);
  130.   }
  131.  }
  132. else
  133. #endif
  134. // Get Command Line Arguments
  135. for (xI=1;xI < argc;xI++) {
  136.  strcat(Line,argv[xI]); strcat(Line," ");
  137.  }
  138.  
  139. #ifndef __MSDOS__
  140. // Open Environment File - read this second so any args override the default env
  141. if (InputFile=fopen("ENV:DLGGuide","rt"))
  142.  while (fgets(xS,255,InputFile)) {
  143.   if (xS[strlen(xS)-1] == '\n') xS[strlen(xS)-1]='\0';
  144.   strcat(Line,xS); strcat(Line," ");
  145.   }
  146. fclose(InputFile);
  147. #endif
  148.  
  149. strupr(Line);
  150.  
  151. // Parse Startup Arguments
  152. #ifndef __MSDOS__
  153. if ((Pointer=strstr(Line," WINDOW=")) != NULL) {
  154.  strcpy(xS,Pointer+8);
  155.  xI=strlen(xS)-strlen(strstr(xS," "));
  156.  strncpy(WindowArg,xS,xI); WindowArg[xI]='\0';
  157.  }
  158. else
  159. if (!argc) sprintf(WindowArg,"CON:10/10/620/180/%s",DONGROUT+6);
  160. else strcpy(WindowArg,"");
  161.  
  162. if (strlen(WindowArg))
  163.  if (!(TxtOut=fopen(WindowArg,"r+"))) {
  164.   sprintf(xS,"DLGGuide Error - TxtOut=%s",WindowArg);
  165.   CleanExit(xS);
  166.   }
  167.  else ;
  168. else
  169. #endif
  170.  TxtOut=stdout;
  171.  
  172. fprintf(TxtOut,"%s\n\n",DONGROUT+6);
  173. fflush(TxtOut);
  174.  
  175. // Parse Arguments
  176. if ((Pointer=strstr(Line," MSGFILE=")) != NULL) {
  177.  strcpy(xS,Pointer+9);
  178.  xI=strlen(xS)-strlen(strstr(xS," "));
  179.  strncpy(FileArg,xS,xI); FileArg[xI]='\0';
  180.  LoadMsgArea(FileArg);
  181.  }
  182. if ((Pointer=strstr(Line," FILE=")) != NULL) {
  183.  strcpy(xS,Pointer+6);
  184.  xI=strlen(xS)-strlen(strstr(xS," "));
  185.  strncpy(FileArg,xS,xI); FileArg[xI]='\0';
  186.  }
  187. else strcpy(FileArg,"");
  188. if ((Pointer=strstr(Line," PATH=")) != NULL) {
  189.  strcpy(xS,Pointer+6);
  190.  xI=strlen(xS)-strlen(strstr(xS," "));
  191.  strncpy(PathArg,xS,xI); PathArg[xI]='\0';
  192.  if (strstr(Line," NOPATH ")) PathFlag=0; else PathFlag=1;
  193.  }
  194. else {
  195.  strcpy(PathArg,""); PathFlag=0;
  196.  }
  197.  
  198. // Test for the Right Arguments
  199. if (strlen(FileArg) == 0) {
  200.  fprintf(TxtOut,"Format Is - DLGGuide FILE=<inputfile> <options>\n\n");
  201.  fprintf(TxtOut,"Options Are:\n");
  202.  fprintf(TxtOut," PATH=<outputpath>  - path of where to send output files\n");
  203.  fprintf(TxtOut," NOPATH             - don't place the path in output files\n");
  204.  fprintf(TxtOut," MSGFILE=<filename> - name of message area file\n");
  205. #ifndef __MSDOS__
  206.  fprintf(TxtOut," WINDOW=<winspec>   - specify the window to use\n");
  207. #endif
  208.  CleanExit(" ");
  209.  }
  210.  
  211. // Open Input File
  212. if (!(InputFile=fopen(FileArg,"rt"))) {
  213.  sprintf(xS,"DLGGuide Error - InputFile=fopen(%s,read)",FileArg);
  214.  CleanExit(xS);
  215.  }
  216.  
  217. // Get Input File Date & Time
  218. #ifdef DOS_DATETIME_H
  219. FIBlock=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),
  220.                                          MEMF_PUBLIC | MEMF_CLEAR);
  221. if (FIBlock) {
  222. DTime=(struct DateTime *)AllocMem(sizeof(struct DateTime),
  223.                                   MEMF_PUBLIC | MEMF_CLEAR);
  224. if (DTime) {
  225. FLock=(struct FileLock *)Lock(FileArg,SHARED_LOCK);
  226. if (FLock) {
  227. if (Examine((BPTR)FLock,FIBlock)) {
  228.  struct Library *LocaleBase;
  229.  DTime->dat_Stamp=FIBlock->fib_Date;
  230.  LocaleBase=OpenLibrary("locale.library",38);
  231.  if (LocaleBase) {
  232.   DTime->dat_Format=4;
  233.   CloseLibrary(LocaleBase);
  234.   }
  235.  else DTime->dat_Format=FORMAT_DOS;
  236.  DTime->dat_Flags=NULL;
  237.  DTime->dat_StrDay=NULL;
  238.  DTime->dat_StrDate=Date;
  239.  DTime->dat_StrTime=Time;
  240.  if (!DateToStr(DTime)) {
  241.   strcpy(Date,"__-___-__"); strcpy(Time,"__:__:__");
  242.   }
  243.  sprintf(FileDate,"%s %s",Date,Time);
  244.  }
  245. UnLock((BPTR)FLock);
  246. }
  247. FreeMem(DTime,sizeof(struct DateTime));
  248. }
  249. FreeMem(FIBlock,sizeof(struct FileInfoBlock));
  250. }
  251. #else
  252. time(&SecsNow);
  253. TimePointer=localtime(&SecsNow);
  254. sprintf(FileDate,"%02d-%3.3s-%02d %02d:%02d:%02d",
  255.  TimePointer->tm_mday,WordMonth(TimePointer->tm_mon+1),TimePointer->tm_year,
  256.  TimePointer->tm_hour,TimePointer->tm_min,TimePointer->tm_sec);
  257. #endif
  258.  
  259. // Open Guide File
  260. #ifndef __MSDOS__
  261. sprintf(FileName,"%s%s.info",PathArg,DLGGUIDE);
  262. if (!(GuideFile=fopen(FileName,"wb"))) {
  263.  fprintf(TxtOut,"DLGGuide Warning - GuideFile.info=fopen(%s,write)\n",FileName);
  264.  fflush(TxtOut);
  265.  }
  266. else {
  267.  for (xI=0; xI<AMIGAGUIDEICON; xI++)
  268.   fputc(AmigaGuideIcon[xI],GuideFile);
  269.  fclose(GuideFile);
  270.  }
  271. #endif
  272. sprintf(FileName,"%s%s",PathArg,DLGGUIDE);
  273. if (!(GuideFile=fopen(FileName,"wt"))) {
  274.  sprintf(xS,"DLGGuide Error - GuideFile=fopen(%s,write)",FileName);
  275.  CleanExit(xS);
  276.  }
  277.  
  278. if (PathFlag) fprintf(GuideFile,"@database \"%s%s\"\n",PathArg,DLGGUIDE);
  279. else fprintf(GuideFile,"@database \"%s\"\n",DLGGUIDE);
  280. master(GuideFile);
  281. ver(GuideFile);
  282.  
  283. fprintf(GuideFile,"@node main \"DLG Messages - %s\"\n",FileDate);
  284. toc(GuideFile);
  285. fprintf(GuideFile,"\nSubjects - Message Areas\n\n");
  286.  
  287. // Get First Message Area
  288. while (fgets(Line,255,InputFile))
  289.  if (strncmp(Line,NEWMSGAREA,strlen(NEWMSGAREA)) == 0)
  290.   break;
  291.  
  292. do {
  293.  strcpy(FileName,GetFileName(Line));
  294.  
  295.  // Open Output File
  296.  sprintf(MsgFileName,"%s%s",PathArg,FileName);
  297.  if (!(OutputFile=fopen(MsgFileName,"wt"))) {
  298.   sprintf(xS,"DLGGuide Error - OutputFile=fopen(%s,write)",MsgFileName);
  299.   CleanExit(xS);
  300.   }
  301.  if (!PathFlag) strcpy(MsgFileName,FileName);
  302.  
  303.  // Open Index File
  304. #ifndef __MSDOS__
  305.  sprintf(IndexFileName,"%s%s.Index",PathArg,FileName);
  306. #else
  307.  sprintf(IndexFileName,"%sIndex",PathArg);
  308. #endif
  309.  if (!(IndexFile=fopen(IndexFileName,"wt"))) {
  310.   sprintf(xS,"DLGGuide Error - IndexFile=fopen(%s,write)",IndexFileName);
  311.   CleanExit(xS);
  312.   }
  313.  if (!PathFlag) sprintf(IndexFileName,"%s.Index",FileName);
  314.  
  315.  if (MsgAreaSize) MsgAreaNum=GetMsgArea(MessageArea);
  316.  else MsgAreaNum=0;
  317.  
  318.  if (MsgAreaNum)
  319.   fprintf(TxtOut,"Working on Message Area %3d [%s]\n",MsgAreaNum,MessageArea);
  320.  else
  321.   fprintf(TxtOut,"Working on Message Area [%s]\n",MessageArea);
  322.  fflush(TxtOut);
  323.  
  324.  fprintf(IndexFile,"@database \"%s\"\n",IndexFileName);
  325.  master(IndexFile);
  326.  ver(IndexFile);
  327.  fprintf(IndexFile,"@node main \"Message Area ");
  328.  if (MsgAreaNum)
  329.   fprintf(IndexFile,"%3d [%s]",MsgAreaNum,MessageArea);
  330.  else
  331.   fprintf(IndexFile,"[%s]",MessageArea);
  332.  fprintf(IndexFile," - Index - %s\"\n",FileDate);
  333.  toc(IndexFile);
  334.  
  335.  fprintf(OutputFile,"@database \"%s\"\n",MsgFileName);
  336.  master(OutputFile);
  337.  ver(OutputFile);
  338.  fprintf(OutputFile,"@index \"%s/main\"\n",IndexFileName);
  339.  if (MsgAreaNum)
  340.   fprintf(OutputFile,"\n@node main \"Message Area %3d [%s]\"\n"
  341.                     ,MsgAreaNum,MessageArea);
  342.  else
  343.   fprintf(OutputFile,"\n@node main \"Message Area [%s]\"\n",MessageArea);
  344.  toc(OutputFile);
  345.  fprintf(OutputFile,"@next subject1\n");
  346.  fprintf(OutputFile,"\n@{\"Index\" link \"%s/main\"}\n",IndexFileName);
  347.  fprintf(OutputFile,"@endnode\n");
  348.  
  349.  // Get Next Message Area
  350.  SubjectCount=0;
  351.  do {
  352.   Flag=fgets(Line,255,InputFile);
  353.   if (!strncmp(Line,NEWSUBJECT,strlen(NEWSUBJECT))) {
  354.    // Start of a Subject Found - get Prev. to [Subject] line
  355.    strcpy(SubjectString[1],Line);
  356.    for (xI=2; xI<=SUBJECTNUM; xI++)
  357.     fgets(SubjectString[xI],255,InputFile);
  358.  
  359.    // Reduce unnessary characters from [Subject] line
  360.    SearchAndReplace(SubjectString[SUBJECTNUM],"\"","");
  361.    strcpy(SubjectString[SUBJECTNUM+1],SubjectString[SUBJECTNUM]);
  362.    strlwr(SubjectString[SUBJECTNUM+1]);
  363.    SearchAndReplace(SubjectString[SUBJECTNUM+1]," ","");
  364.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"re:","");
  365.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"~","");
  366.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"`","");
  367.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"!","");
  368.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"@","");
  369.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"#","");
  370.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"$","");
  371.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"%","");
  372.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"^","");
  373.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"&","");
  374.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"*","");
  375.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"(","");
  376.    SearchAndReplace(SubjectString[SUBJECTNUM+1],")","");
  377.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"_","");
  378.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"-","");
  379.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"+","");
  380.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"=","");
  381.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"{","");
  382.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"[","");
  383.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"}","");
  384.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"]","");
  385.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"|","");
  386.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"\\","");
  387.    SearchAndReplace(SubjectString[SUBJECTNUM+1],":","");
  388.    SearchAndReplace(SubjectString[SUBJECTNUM+1],";","");
  389.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"'","");
  390.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"<","");
  391.    SearchAndReplace(SubjectString[SUBJECTNUM+1],",","");
  392.    SearchAndReplace(SubjectString[SUBJECTNUM+1],">","");
  393.    SearchAndReplace(SubjectString[SUBJECTNUM+1],".","");
  394.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"?","");
  395.    SearchAndReplace(SubjectString[SUBJECTNUM+1],"/","");
  396.  
  397.    if (stricmp(SubjectString[SUBJECTNUM+1],SubjectString[0])) {
  398.     // New Subject Found
  399.     SubjectCount++;
  400.     AddIndex(SubjectCount,SubjectString[SUBJECTNUM],MsgFileName);
  401.     if (SubjectCount != 1)
  402.      fprintf(OutputFile,"@endnode\n");
  403.     fprintf(OutputFile,"@node subject%d \"Message Area ",SubjectCount);
  404.     if (MsgAreaNum)
  405.      fprintf(OutputFile,"%3d [%s]",MsgAreaNum,MessageArea);
  406.     else
  407.      fprintf(OutputFile,"[%s]",MessageArea);
  408.     fprintf(OutputFile," - Subject %d - %s\"\n",SubjectCount,FileDate);
  409.     toc(OutputFile);
  410.     if (SubjectCount != 1)
  411.      fprintf(OutputFile,"@prev subject%d\n",SubjectCount-1);
  412.     fprintf(OutputFile,"@next subject%d\n",SubjectCount+1);
  413.     strcpy(SubjectString[0],SubjectString[SUBJECTNUM+1]);
  414.     }
  415.  
  416.    // Write Subject Header
  417.    for (xI=1; xI<SUBJECTNUM; xI++)
  418.     fprintf(OutputFile,"%s",SubjectString[xI]);
  419.    fprintf(OutputFile,"@{\"%s\" link \"%s/main\" %d}%s",SUBJECT,IndexFileName,
  420.                          SubjectCount-1,SubjectString[SUBJECTNUM]+strlen(SUBJECT));
  421.  
  422.    if (IsSkip(MsgAreaNum)) SkipParagraph(InputFile,OutputFile);
  423.    continue;
  424.    }
  425.   if (strncmp(Line,NEWMSGAREA,strlen(NEWMSGAREA)) == 0)
  426.    break;
  427.   else
  428.    fprintf(OutputFile,"%s",Line);
  429.   } while (Flag);
  430.  
  431.  fprintf(OutputFile,"@endnode\n");
  432.  fprintf(OutputFile,"@node subject%d \"Message Area ",SubjectCount+1);
  433.  if (MsgAreaNum)
  434.   fprintf(OutputFile,"%3d [%s]",MsgAreaNum,MessageArea);
  435.  else
  436.   fprintf(OutputFile,"[%s]",MessageArea);
  437.  fprintf(OutputFile," - %s\"\n",FileDate);
  438.  toc(OutputFile);
  439.  if (PathFlag)
  440.   fprintf(OutputFile,"@next \"%s%s/main\"",PathArg,DLGGUIDE);
  441.  else
  442.   fprintf(OutputFile,"@next \"%s/main\"",DLGGUIDE);
  443.  fprintf(OutputFile,"@prev subject%d\n",SubjectCount);
  444.  fprintf(OutputFile,"\nThat's All Folks!\n\n");
  445.  if (PathFlag)
  446.   fprintf(OutputFile,"@{\"   OK   \" link \"%s%s/main\"}",PathArg,DLGGUIDE);
  447.  else
  448.   fprintf(OutputFile,"@{\"   OK   \" link \"%s/main\"}",DLGGUIDE);
  449.  fprintf(OutputFile,"     @{\" Again! \" link subject1}");
  450.  fprintf(OutputFile,"     @{\" Index  \" link \"%s/main\" %d}\n",IndexFileName
  451.                                                                 ,SubjectCount-1);
  452.  fprintf(OutputFile,"@endnode\n");
  453.  fclose(OutputFile);
  454.  
  455.  fprintf(IndexFile,"@endnode\n");
  456.  fclose(IndexFile);
  457.  
  458.  fprintf(GuideFile,"@{\"  %4d  \" link \"%s/main\"}",SubjectCount,IndexFileName);
  459.  fprintf(GuideFile," @{\"-\" system \"delete %s#?\"} ",MsgFileName); // VERSION 2.32
  460.  if (MsgAreaNum)
  461.   fprintf(GuideFile,"@{\"%3d. %s\" link \"%s/subject1\"}\n",MsgAreaNum
  462.                                                          ,MessageArea,MsgFileName);
  463.  else
  464.   fprintf(GuideFile,"@{\"     %s\" link \"%s/subject1\"}\n",MessageArea
  465.                                                            ,MsgFileName);
  466.  } while (Flag);
  467.  
  468. fprintf(GuideFile,"@endnode\n");
  469. CleanExit("");
  470. return 0;
  471. }
  472.  
  473. // Function Declaration *****************************************************
  474.  
  475. char *GetFileName(char *String) // ******************************************
  476. {
  477. char xS[255];
  478. int xI;
  479.  
  480. // Get Actual Message Area
  481. strcpy(MessageArea,String+strlen(NEWMSGAREA));
  482. for (xI=0; xI < strlen(MessageArea); xI++)
  483.  if (MessageArea[xI] == ENDMSGAREA) {
  484.   MessageArea[xI]='\0'; break;
  485.   }
  486.  
  487. // Get Shortened FileName
  488. strcpy(xS,MessageArea);
  489. SearchAndReplace(xS," ","");
  490. SearchAndReplace(xS,"/","-");
  491. SearchAndReplace(xS,"\\","-");
  492. SearchAndReplace(xS,"(",".");
  493. SearchAndReplace(xS,")","");
  494. SearchAndReplace(xS,"Comp.Sys.Amiga.","CSA");
  495. SearchAndReplace(xS,"Amiga","A-");
  496. SearchAndReplace(xS,"General","Gen");
  497. SearchAndReplace(xS,"GreatValleyProducts","GVP");
  498. SearchAndReplace(xS,"International","Int");
  499. SearchAndReplace(xS,"National","Nat");
  500. SearchAndReplace(xS,"Programmer","Prog");
  501. SearchAndReplace(xS,"Saskatchewan","Sask");
  502. SearchAndReplace(xS,"Saskatoon","Stoon");
  503. SearchAndReplace(xS,"S.A.U.G","SAUG");
  504.  
  505. return xS;
  506. }
  507.  
  508. void master(FILE *File) // **************************************************
  509. { fprintf(File,"@master \"%s\"\n",FileArg); }
  510.  
  511. void toc(FILE *File) // *****************************************************
  512. {
  513. if (PathFlag) fprintf(File,"@toc \"%s%s/main\"\n",PathArg,DLGGUIDE);
  514. else fprintf(File,"@toc \"%s/main\"\n",DLGGUIDE);
  515. }
  516.  
  517. void ver(FILE *File) // *****************************************************
  518. { fprintf(File,"@%s\n",DONGROUT); }
  519.  
  520. void AddIndex(int Num,char *Subject,char *File) // **************************
  521. {
  522. unsigned char xS[255];
  523.  
  524. strcpy(xS,Subject+strlen(NEWSUBJECT));
  525. SearchAndReplace(xS,"Re: ","");
  526. SearchAndReplace(xS,"re: ","");
  527. SearchAndReplace(xS,"RE: ","");
  528. SearchAndReplace(xS,"Re:","");
  529. SearchAndReplace(xS,"re:","");
  530. SearchAndReplace(xS,"RE:","");
  531. SearchAndReplace(xS,"  "," ");
  532. if (xS[strlen(xS)-1] == '\n') xS[strlen(xS)-1]='\0';
  533. fprintf(IndexFile,"Subject %3d. @{\"%s\" link \"%s/subject%d\"}\n"
  534.                  ,Num,xS,File,Num);
  535. }
  536.  
  537. void LoadMsgArea(char FileName[80]) // *****************************************
  538. {
  539. FILE *File;
  540. char xS[80];
  541.  
  542. if (!(File=fopen(FileName,"rt"))) {
  543.  sprintf(xS,"DLGGuide Error - MsgAreaFile=fopen(%s,read)",FileName);
  544.  CleanExit(xS);
  545.  }
  546. MsgAreaSize=0;
  547. while (fgets(xS,80,File))
  548.  if (strlen(xS) && (xS[0]>='0' && xS[0]<='9')) {
  549.   if (xS[strlen(xS)-1] == '\n') xS[strlen(xS)-1]='\0';
  550.   MsgAreaSize++;
  551.   MsgAreaList[MsgAreaSize].Num=atoi(xS);
  552.   if (strstr(xS,"*\t"))
  553.    MsgAreaList[MsgAreaSize].Skip=1; else MsgAreaList[MsgAreaSize].Skip=0;
  554.   strcpy(MsgAreaList[MsgAreaSize].Data,strstr(xS,"\t")+1);
  555.   }
  556.  
  557. fclose(File);
  558. }
  559.  
  560. int GetMsgArea(char xS[80]) // **********************************************
  561. {
  562. int xI;
  563.  
  564. for (xI=1; xI<=MsgAreaSize; xI++)
  565.  if (!stricmp(xS,MsgAreaList[xI].Data)) // VERSION 2.31
  566.   return MsgAreaList[xI].Num;
  567. return 0;
  568. }
  569.  
  570. int IsSkip(int Num) // ******************************************************
  571. {
  572. int xI;
  573.  
  574. for (xI=1; xI<=MsgAreaSize; xI++)
  575.  if (MsgAreaList[xI].Num == Num)
  576.   return MsgAreaList[xI].Skip;
  577. return 0;
  578. }
  579.  
  580. void SkipParagraph(FILE *In,FILE *Out) // ***********************************
  581. {
  582. char xS[255];
  583.  
  584. // Blank Line
  585. fgets(xS,255,In);
  586. fputs(xS,Out);
  587.  
  588. // Paragraph
  589. while (fgets(xS,255,In)) {
  590.  if (strlen(xS) <= 1) {
  591.   fputs(xS,Out); break;
  592.   }
  593.  if (!strnicmp(xS,"From: ",6) ||
  594.      !strnicmp(xS,"Organization: ",14))
  595.   fputs(xS,Out);
  596.  }
  597. }
  598.  
  599. int SearchAndReplace(char *String,char Search[255],char Replace[255]) // ****
  600. { // Search & Replace function for Strings of text
  601. char Prefix[255]="", Suffix[255]="";
  602.  
  603. /* Replace string can't contain Search string
  604.    Otherwise an infinite loop is created */
  605. if (strstr(Replace,Search)) return FALSE;
  606.  
  607. while (strstr(String,Search)) {
  608.  strcpy(Suffix,strstr(String,Search)+strlen(Search));
  609.  strcpy(Prefix,String);
  610.  Prefix[strlen(String)-strlen(Suffix)-strlen(Search)]='\0';
  611.  sprintf(String,"%s%s%s",Prefix,Replace,Suffix);
  612.  }
  613. return TRUE;
  614. }
  615.  
  616. char *WordMonth(int x) // Get A Number And Return The Name Of The Month ******
  617. {static char *MonthNames[]={"","January","February","March","April","May",
  618. "June","July","August","September","October","November","December"};
  619. return ((x<1 || x>12) ? MonthNames[0] : MonthNames[x]);}
  620.  
  621. void CleanExit(char *ErrorMsg) // *******************************************
  622. {
  623. if (InputFile)  fclose(InputFile);
  624. if (OutputFile) fclose(OutputFile);
  625. if (IndexFile)  fclose(IndexFile);
  626. if (GuideFile)  fclose(GuideFile);
  627. #ifndef __MSDOS__
  628. #endif
  629. if (strcmp(ErrorMsg,"")) {
  630.  fprintf(TxtOut,"%s\n",ErrorMsg);
  631.  fflush(TxtOut);
  632. #ifndef __MSDOS__
  633.  if (strlen(WindowArg)) Delay(5*50);
  634. #endif
  635.  exit(10);
  636.  }
  637. else
  638.  exit(0);
  639. }
  640.