home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / utilities / hypertext / iv2ag / iv2ag.c next >
Encoding:
C/C++ Source or Header  |  1994-06-22  |  4.3 KB  |  214 lines

  1. /*
  2.  
  3.     by Alexander Rawass, a_rawass@informatik.uni-kl.de
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <exec/types.h>
  8.  
  9. #include "/ar_defs.h"
  10.  
  11. #define    LMAX 200
  12.  
  13. int    count,fromcount;
  14. FILE    *omfh;
  15. FILE    *mainfh;
  16. char    buf[LMAX];
  17. char    from[LMAX];
  18. char    node[LMAX];
  19. char    previous[LMAX];
  20. char    up[LMAX];
  21. char    file[LMAX];
  22. char    next[LMAX];
  23. char    dummy[LMAX];
  24. int    buflen;
  25. BOOL    header_skipped=FALSE;
  26. BOOL    komma;
  27. int    lines;
  28. BOOL    is_menu;
  29. char    menu[LMAX];
  30. BOOL    is_note;
  31. char    note[LMAX];
  32.  
  33. VOID    stripM(buf)
  34. STRPTR    buf;
  35. {
  36.     int    i;
  37.  
  38.     for(i=0;buf[i]!='\n' && buf[i]!=0;i++){
  39.         if(buf[i]==0x0d){
  40.             buf[i]=0;
  41.         }
  42.     }
  43.     buf[i]=0;
  44. }
  45.  
  46. VOID    nospace(buf)
  47. STRPTR    buf;
  48. {
  49. int    i;
  50.  
  51.     for(i=0;buf[i]!=EOS;i++){
  52.         if(buf[i]==' '){
  53.             buf[i]='_';
  54.         }
  55.     }
  56. }
  57.  
  58. int    main(argc,argv)
  59. int    argc;
  60. STRPTR    argv[];
  61. {
  62. int    i,j,k;
  63. int    lasti;
  64. int    a,b,c,d;
  65.  
  66.     if(argc!=3){
  67.         printf("Usage: %s <infoview-file> <amigaguide-file>\n",argv[0]);
  68.         exit(NULL);
  69.     }
  70.     
  71.     count=0;
  72.     fromcount=0;
  73.  
  74.     omfh=fopen(argv[1],"r");
  75.     mainfh=fopen(argv[2],"w");
  76.  
  77.     if(!(omfh && mainfh)){
  78.         printf("ERROR: could not open files\n");
  79.         exit(4);
  80.     }
  81.     
  82.     strcpy(from,"----");
  83.  
  84.     fprintf(mainfh,"@node main \042%s\042\n\n",argv[1]);
  85.     
  86.     fgets(buf,LMAX,omfh);
  87.     while(!feof(omfh)){
  88.         lines++;
  89.         stripM(buf);
  90.         if(buf[0]==0x1f){
  91. /*            if(count>0){
  92.                 fprintf(mainfh,"@endnode\n");
  93.             }
  94. */
  95.                 fprintf(mainfh,"@endnode\n");
  96.             count++;
  97.         }
  98.         else if(STRNEQU("File:",buf,strlen("File:"))){
  99.         header_skipped=TRUE;
  100.         up[0]=EOS;
  101.         node[0]=EOS;
  102.         previous[0]=EOS;
  103.         i=0;
  104.         buflen=strlen(buf);
  105. while(i<buflen){
  106.                 for(a=i;buf[a]!=' ' && buf[a]!='\t' && buf[a]!=',';a++)    ;
  107.                 if(buf[a]==','){
  108.                     komma=TRUE;
  109.                 }
  110.                 buf[a]=EOS;
  111.                 /* in buf[i:a] steht nun Node:, File:, Next: etc. */
  112.                 
  113. /*                for(b=a+1;buf[b]==' ';b++)    ;    */
  114.                 b=a+1;
  115.                 /* buf[b] ist der anfang des inhalts des keywords */                
  116.                 
  117. /*                for(c=b;buf[c]!=' ' && buf[c]!='\t' && buf[c]!=',' && c<buflen;c++)    ;    */
  118.                 for(c=b;buf[c]!='\t' && buf[c]!=',' && c<buflen;c++)    ;
  119.                 buf[c]=EOS;
  120.                 /* buf[b:c] ist der inhalt des keywords */
  121.                 
  122.                 for(d=c+1;c<buflen && (buf[d]==' ' || buf[d]=='\t' || buf[d]==',');d++)    ;
  123.                 /* mit buf[d] gehts wieder in den loop */
  124.                 
  125.                 nospace(&(buf[b]));
  126.                 if(STRNEQU(&(buf[i]),"File:",strlen("File:"))){
  127.                     strcpy(file,&(buf[b]));
  128.                 }
  129.                 else if(STRNEQU(&(buf[i]),"Node:",strlen("Node:"))){
  130.                     strcpy(node,&(buf[b]));
  131.                     printf("Node: %s\n",node);
  132.                 }
  133.                 else if(STRNEQU(&(buf[i]),"Up:",strlen("Up:"))){
  134.                     strcpy(up,&(buf[b]));
  135.                 }
  136.                 else if(STRNEQU(&(buf[i]),"Previous:",strlen("Previous:"))){
  137.                     strcpy(previous,&(buf[b]));
  138.                 }
  139.                 else if(STRNEQU(&(buf[i]),"Prev:",strlen("Prev:"))){
  140.                     strcpy(previous,&(buf[b]));
  141.                 }
  142.                 else if(STRNEQU(&(buf[i]),"Next:",strlen("Next:"))){
  143.                     strcpy(next,&(buf[b]));
  144.                 }
  145.                 else{
  146.                     printf("WARNING: unknown command %s line %d\n",buf[i],lines);
  147.                 }
  148.                 
  149.                 i=d;
  150.             }
  151.                 
  152.             fprintf(mainfh,"@node %s-%s \042%s-%s\042\n",file,node,file,node);
  153.             if(up[0]!=EOS){
  154.                 fprintf(mainfh,"Up: @{\042%-12s\042 LINK %s-%s}     ",up,file,up);
  155.             }
  156.             if(next[0]!=EOS){
  157.                 fprintf(mainfh,"Next: @{\042%-12s\042 LINK %s-%s}     ",next,file,next);
  158.             }
  159.             if(previous[0]!=EOS){
  160.                 fprintf(mainfh,"Prev: @{\042%-12s\042 LINK %s-%s}     ",previous,file,previous);
  161.             }
  162.             fprintf(mainfh,"\n\n");
  163.         }
  164.         else if(STRNEQU(buf,"* ",2) && !(STRNEQU("* Menu:",buf,strlen("* Menu:")))){
  165.             /* maybe a menu? */
  166.             is_menu=FALSE;
  167.             for(i=1;buf[i]!=EOS && is_menu==FALSE;i++){
  168.                 if(buf[i]==':' /* && buf[i-1]==':' */){
  169.                     is_menu=TRUE;
  170.                     buf[i]=EOS;
  171.                     nospace(&(buf[2]));
  172.                     strcpy(menu,&(buf[2]));
  173.                     if(buf[i+1]==':'){
  174.                         buf[i+1]=EOS;
  175.                     }
  176.                 }
  177.             }
  178.             if(is_menu){
  179.                 fprintf(mainfh,"  @{\042%s\042 LINK %s-%s}",menu,file,menu);
  180.                 fprintf(mainfh,"  %s\n",&(buf[i+1]));
  181.             }
  182.             else{
  183.                 fprintf(mainfh,"%s\n",buf);
  184.             }
  185.         }
  186.         else{
  187.             is_note=FALSE;
  188.             for(i=0;buf[i]!=EOS && is_note==FALSE;i++){
  189.                 if(STRNEQU(&(buf[i]),"*Note ",strlen("*Note "))){
  190.                     is_note=TRUE;
  191.                     buf[i]=EOS;
  192.                     for(j=i+6;buf[j]!=':' && buf[j]!=EOS;j++)    ;
  193.                     buf[j]=EOS;
  194.                     strcpy(note,&(buf[i+6]));
  195.                 }
  196.             }
  197.             if(is_note==TRUE){
  198.                 fprintf(mainfh,"%s",buf);
  199.                 fprintf(mainfh,"  @{\042%s\042 LINK %s-%s}",note,file,note);
  200.                 fprintf(mainfh,"%s\n",&(buf[j+3]));
  201.             }
  202.             else{
  203.                 fprintf(mainfh,"%s\n",buf);
  204.             }
  205.         }
  206.         fgets(buf,LMAX,omfh);
  207.     }
  208.     
  209.     fprintf(mainfh,"@endnode\n");
  210.  
  211.     fclose(omfh);
  212.     fclose(mainfh);
  213. }
  214.