VIEWS 22-SEP-1995 18:31:30 VAX C V3.2-044 Page 1 V1.0 13-OCT-1994 00:26:38 [GOPHER.G2.VMS2_13.OBJECT]VIEWS.C;1 (1) 1 /******************************************************************** 2 * lindner 3 * 3.12 4 * 1994/10/13 05:26:38 5 * /home/arcwelder/GopherSrc/CVS/gopher+/object/VIews.c,v 6 * Exp 7 * 8 * Paul Lindner, University of Minnesota CIS. 9 * 10 * Copyright 1991, 1992, 1993 by the Regents of the University of Minnesota 11 * see the file "Copyright" in the distribution for conditions of use. 12 ********************************************************************* 13 * MODULE: VIews.c 14 * Various functions to handle gopher+ views 15 ********************************************************************* 16 * Revision History: 17 * VIews.c,v 18 * Revision 3.12 1994/10/13 05:26:38 lindner 19 * Compiler complaint fixes 20 * 21 * Revision 3.11 1994/07/21 22:33:38 lindner 22 * Update for Language strings 23 * 24 * Revision 3.10 1994/06/29 06:55:25 lindner 25 * made VIprettyLang non-case-sensitive when checking lang codes 26 * 27 * Accept views without sizes (since the Gopher+ protocol docs say 28 * they're acceptable) (Coopersmith) 29 * 30 * Revision 3.9 1994/03/08 17:24:03 lindner 31 * View language strangeness fixes from Dave Shield 32 * 33 * Revision 3.8 1994/03/04 17:44:21 lindner 34 * Fix for size processing 35 * 36 * Revision 3.7 1994/01/21 04:09:29 lindner 37 * Fix for bad VIEWS blocks 38 * 39 * Revision 3.6 1993/12/27 16:21:58 lindner 40 * Fix bug where no language in gopherd.conf would crash the server 41 * 42 * Revision 3.5 1993/08/24 21:03:52 lindner 43 * Fix spelling typo 44 * 45 * Revision 3.4 1993/07/29 20:00:06 lindner 46 * none 47 * 48 * Revision 3.3 1993/07/23 04:49:06 lindner 49 * Added PrettyView fcn 50 * 51 * Revision 3.2 1993/03/24 17:09:01 lindner 52 * Fixed a memory leak 53 * 54 * Revision 3.1.1.1 1993/02/11 18:03:01 lindner 55 * Gopher+1.2beta release VIEWS 22-SEP-1995 18:31:30 VAX C V3.2-044 Page 2 V1.0 13-OCT-1994 00:26:38 [GOPHER.G2.VMS2_13.OBJECT]VIEWS.C;1 (1) 56 * 57 * Revision 2.1 1993/02/09 22:48:50 lindner 58 * Changes for multilingual views 59 * 60 * Revision 1.1 1993/01/31 00:31:12 lindner 61 * Initial revision 62 * 63 * 64 *********************************************************************/ 65 66 #include "VIews.h" 345 #include "Malloc.h" 1368 #include "String.h" 1885 #include "BLblock.h" 3805 3806 3807 static char *ANSILangs[] = { 3808 "Da_DK", "Nl_BE", "Nl_NL", "En_GB", "En_US", "Fi_FI", "Fr_BE", 3809 "Fr_CA", "Fr_CH", "Fr_FR", "De_CH", "De_DE", "El_GR", "Is_IS", 3810 "It_IT", "Jp_JP", "No_NO", "Pt_PT", "Es_ES", "Sv_SE", "Tr_TR", 3811 NULL 3812 }; 3813 3814 static char *ANSILangEn[] = { 3815 "Danish", 3816 "Dutch (Belgium)", 3817 "Dutch", 3818 "English (Great Britain)", 3819 "English (USA)", 3820 "Finnish", 3821 "Français (Belgium)", 3822 "Français (Canada)", 3823 "Français (Suisse)", 3824 "Français", 3825 "Deutsch (Suisse)", 3826 "Deutsch", 3827 "Greek", 3828 "Icelandic", 3829 "Italiano", 3830 "Japanese", 3831 "Norwegian", 3832 "Portugues", 3833 "Español", 3834 "Swedish", 3835 "Turkish", 3836 NULL 3837 }; 3838 3839 3840 char * 3841 VIprettyLang(vi, currentlang) 3842 VIewobj *vi; 3843 char *currentlang; 3844 { 3845 1 int i; 3846 1 char *cp = VIgetLang(vi); 3847 1 VIEWS 22-SEP-1995 18:31:30 VAX C V3.2-044 Page 3 V1.0 13-OCT-1994 00:26:38 [GOPHER.G2.VMS2_13.OBJECT]VIEWS.C;1 (1) 3848 1 if (VIgetLang(vi) == NULL) 3849 1 return(NULL); 3850 1 for (i=0; ;i++) { 3851 2 if (ANSILangs[i] == NULL) 3852 2 return(NULL); 3853 2 3854 2 if (strcasecmp(ANSILangs[i], cp) == 0) 3855 2 return(ANSILangEn[i]); 3856 2 } 3857 1 } 3858 3859 3860 3861 3862 VIewobj * 3863 VInew() 3864 { 3865 1 VIewobj *temp; 3866 1 3867 1 temp = (VIewobj *) malloc(sizeof(VIewobj)); 3868 1 3869 1 temp->Type = STRnew(); 3870 1 temp->Lang = STRnew(); 3871 1 temp->Size = STRnew(); 3872 1 temp->comments = STRnew(); 3873 1 3874 1 VIinit(temp); 3875 1 return(temp); 3876 1 } 3877 3878 /*** Initialize the VIewobj ***/ 3879 3880 void 3881 VIinit(vi) 3882 VIewobj *vi; 3883 { 3884 1 STRinit(vi->Type); 3885 1 STRinit(vi->Lang); 3886 1 STRinit(vi->Size); 3887 1 STRinit(vi->comments); 3888 1 } 3889 3890 3891 /** Destroy the VIewobj ***/ 3892 3893 void 3894 VIdestroy(vi) 3895 VIewobj *vi; 3896 { 3897 1 STRdestroy(vi->Type); 3898 1 STRdestroy(vi->Lang); 3899 1 STRdestroy(vi->Size); 3900 1 STRdestroy(vi->comments); 3901 1 3902 1 free(vi); 3903 1 } 3904 VIEWS 22-SEP-1995 18:31:30 VAX C V3.2-044 Page 4 V1.0 13-OCT-1994 00:26:38 [GOPHER.G2.VMS2_13.OBJECT]VIEWS.C;1 (1) 3905 3906 /** copy a VIewobj **/ 3907 3908 void 3909 VIcpy(videst, viorig) 3910 VIewobj *videst, *viorig; 3911 { 3912 1 STRcpy(videst->Type, viorig->Type); 3913 1 STRcpy(videst->Lang, viorig->Lang); 3914 1 STRcpy(videst->Size, viorig->Size); 3915 1 STRcpy(videst->comments, viorig->comments); 3916 1 } 3917 3918 3919 /** Put a VIewobj in a line according to G+ protocol **/ 3920 3921 void 3922 VItoLine(vi, tmpstr) 3923 VIewobj *vi; 3924 char *tmpstr; 3925 { 3926 1 char *cp; 3927 1 3928 1 tmpstr[0] = ' '; 3929 1 tmpstr[1] = '\0'; 3930 1 3931 1 strcat(tmpstr, VIgetType(vi)); 3932 1 3933 1 cp = VIgetLang(vi); 3934 1 if (cp != NULL && *cp != '\0') { 3935 2 strcat(tmpstr, " "); 3936 2 strcat(tmpstr, cp); 3937 2 } 3938 1 3939 1 /** Size **/ 3940 1 cp = VIgetSize(vi); 3941 1 if (cp != NULL && *cp != '\0') { 3942 2 strcat(tmpstr, ": <"); 3943 2 strcat(tmpstr, VIgetSize(vi)); 3944 2 strcat(tmpstr, ">"); 3945 2 } else { 3946 2 strcat(tmpstr, ": "); 3947 2 } 3948 1 3949 1 /** Comments **/ 3950 1 cp = VIgetComments(vi); 3951 1 if (cp != NULL && *cp != '\0') { 3952 2 strcat(tmpstr, " "); 3953 2 strcat(tmpstr, cp); 3954 2 } 3955 1 } 3956 3957 3958 /** Siphon a G+ view line into a VIewobj **/ 3959 3960 boolean 3961 VIfromLine(vi, line) VIEWS 22-SEP-1995 18:31:30 VAX C V3.2-044 Page 5 V1.0 13-OCT-1994 00:26:38 [GOPHER.G2.VMS2_13.OBJECT]VIEWS.C;1 (1) 3962 VIewobj *vi; 3963 char *line; 3964 { 3965 1 char tmpstr[256], *cp; 3966 1 int i; 3967 1 3968 1 /** Okay, read until the next space, put the result in tmpstr **/ 3969 1 for (cp = line,i=0; (*cp != ' '&&*cp!='\0'&&*cp!=':'); cp++,i++) 3970 1 tmpstr[i] = *cp; 3971 1 3972 1 tmpstr[i]='\0'; 3973 1 line = cp+1; 3974 1 VIsetType(vi, tmpstr); 3975 1 3976 1 if (*line == '\0') 3977 1 return(FALSE); 3978 1 3979 1 3980 1 /** Parse language **/ 3981 1 if (*line != ':') { 3982 2 for (cp = line,i=0; (*cp != ' '&&*cp!='\0'&& *cp!=':'); cp++,i++) 3983 2 tmpstr[i] = *cp; 3984 2 tmpstr[i]='\0'; 3985 2 line = cp+1; 3986 2 VIsetLang(vi, tmpstr); 3987 2 } 3988 1 3989 1 if (*line == '\0') 3990 1 return(FALSE); 3991 1 3992 1 /** Okay, parse off the size (if present) **/ 3993 1 cp = strchr(line,'<'); 3994 1 3995 1 if (cp != NULL) { 3996 2 for (cp++,i=0; (*cp!='\0'&& *cp!='>'); cp++,i++) 3997 2 tmpstr[i] = *cp; 3998 2 tmpstr[i]='\0'; 3999 2 line = cp+1; 4000 2 VIsetSize(vi, tmpstr); 4001 2 } 4002 1 4003 1 if (*line != '\0') 4004 1 VIsetComments(vi, line); 4005 1 4006 1 return(TRUE); 4007 1 } 4008 4009 char * 4010 VIgetViewnLang(vi, line) 4011 VIewobj *vi; 4012 char *line; 4013 { 4014 1 char *cp; 4015 1 4016 1 if (VIgetType(vi) == NULL) 4017 1 return(""); 4018 1 strcpy(line, VIgetType(vi)); VIEWS 22-SEP-1995 18:31:30 VAX C V3.2-044 Page 6 V1.0 13-OCT-1994 00:26:38 [GOPHER.G2.VMS2_13.OBJECT]VIEWS.C;1 (1) 4019 1 4020 1 cp = VIgetLang(vi); 4021 1 if (cp != NULL && *cp != '\0') { 4022 2 strcat(line, " "); 4023 2 strcat(line, VIgetLang(vi)); 4024 2 } 4025 1 return(line); 4026 1 } 4027 4028 4029 /* 4030 * Generates a View Array from a Block 4031 */ 4032 4033 void 4034 VIAfromBL(via,bl) 4035 VIewArray *via; 4036 Blockobj *bl; 4037 { 4038 1 int i; 4039 1 char *cp; 4040 1 VIewobj *vi; 4041 1 4042 1 if (strcasecmp(BLgetName(bl),"VIEWS")!=0) 4043 1 return; 4044 1 4045 1 vi = VInew(); 4046 1 4047 1 for (i=0; i