#include #include #include #include #include #include "projet.h" #include "projetx.m" /* #Sp‚cification: Archivage / R‚pertoires Voici la liste des r‚pertoires associ‚ au systŠme d'archive. /kit/ombre: Contient les combinaisons de toutes les r‚visions des sources. /kit/build: Contient certaines r‚visions en usages. /kit/groupe: Contient un information identique … /kit/ombre en format RCS. D‚suet. /kitobj: Contient les objets de compilation DOS associ‚s … r‚visions de /kit/build. /kit/livre: Contient une copie des livraisons r‚alis‚es par les usagers. /kit/sync: Contient l'information sur le statut des sites satellites. Ca permet de controler les mises … jour qu'on leur envoie (portion d'archive). */ # /* Localise le r‚pertoire projet pour un usager donn‚. On fait l'hypothŠse que tout les r‚pertoires usagers sont dans le mˆme volume. Retourne 0 si ok, -1 si erreur (r‚pertoire existe pas). */ PUBLIC int USERINFO::makusrpath ( const char *autre, // nom du programmeur, autre que courant const char *projet, // R‚pertoire … ajouter au resultat char *userdir) const // contiendra le path complet { char path[MAXSIZ_PATH]; // On recule de deux crans car usrpath contient le nom et la version. path_splitlex (usrpath,path,NULL); path_splitlex (path,path,NULL); path_make (path,autre,path); path_make (path,revpath,path); path_make (path,projet,userdir); return file_type(userdir)==1 ? 0 : -1; } /* Trouve sur quel drive il y a le r‚pertoire des fichier obj\revpath Retourne le drive si ok, -1 si erreur */ PROTECTED int USERINFO::findobj () { int ret = -1; #ifdef MSDOS /* #Sp‚cification: Archivage / R‚pertoires / /kitobj MSDOS Les r‚pertoires d'objets sont localis‚s dynamiquement en balayant les disques. Attention: Tous les utilitaires ne sont pas aussi malin. Les rŠgles de mak (void adm/rules/...) assume un certain nombre de possibilit‚ tel C: D: et N: */ if (objpath != NULL) free(objpath); objpath = NULL; int possible = -1; // Localise r‚pertoire obj si obj\revpath existe pas char *baseobj = isbuild() ? "kitobj" : "obj"; for (int i=0; i<26; i++){ if (drive_type(i)>=1){ /* disque fixe ou network */ char objdir[MAXSIZ_PATH]; sprintf (objdir,"%c:\\%s",i+'a',baseobj); if (file_type(objdir)==1){ if (possible == -1) possible = i; sprintf (objdir,"%c:\\%s\\bc30\\%s",i+'a',baseobj,revpath); if (file_type(objdir)==1){ objpath = strdup_err (objdir); ret = i; break; } } } } if (objpath == NULL && possible != -1){ char objdir[MAXSIZ_PATH]; sprintf (objdir,"%c:\\%s\\bc30\\%s",possible+'a',baseobj,revpath); objpath = strdup_err (objdir); } #else /* #sp‚cification: Archivage / R‚pertoires / /kitobj UNIX Dans l'environnement UNIX, l'emplacement des diff‚rents r‚pertoire d'objet est fixe. On se fie sur les liens symboliques pour configurer. */ char path[MAXSIZ_PATH]; sprintf (path,"/home/obj/%s/gnu/%s",prog,revpath); objpath = strdup_err (path); if (file_type(path)==1){ ret = 0; } #endif return ret; } /* D‚termine le path d'un projet dans l'environnement d'un usager */ PUBLIC void USERINFO::makusrpath ( const char *projet, char *path) const { assert (usrpath != NULL); path_make (usrpath,projet,path); } /* D‚termine le path d'un projet dans l'environnement de livraison. */ PUBLIC void USERINFO::maklivpath ( const char *projet, char *path) const { assert (livre != NULL); path_make (livre,projet,path); } /* D‚termine le path de l'environnement d'exportation pour un site */ PUBLIC void USERINFO::maksyncpath ( const char *site, char *path) const { assert (sync != NULL); path_make (sync,site,path); } /* Retourne le path du r‚pertoire de synchronisation de sites satellites. A peu prŠs ‚quivalent … USERINFO::maksyncpath ("",path). */ PUBLIC const char *USERINFO::getsyncpath() const { return sync; } /* Retourne le path de la racine des projets dans l'environnement usager. A peu prŠs ‚quivalent … USERINFO::makusrpath ("",path). */ PUBLIC const char *USERINFO::getusrpath() const { return usrpath; } /* D‚termine le path d'un projet dans la r‚f‚rence */ PUBLIC void USERINFO::makrefpath ( const char *projet, char *path) const { path_make (groupe,projet,path); } /* D‚termine le path d'un projet dans le r‚pertoire ombre */ PUBLIC void USERINFO::makombpath ( const char *projet, char *path) const { path_make (ombre,projet,path); } /* D‚termine le path d'un projet dans le r‚pertoire build */ PUBLIC void USERINFO::makbldpath ( const char *projet, char *path) const { char revstr[20]; rev.formatbld(revstr); path_make (build,revstr,path); path_make (path,projet,path); } /* D‚termine le path d'un projet dans l'environnement d'un usager Retourne -1 si pas disponible,0 si obj existe, 1 si obj\projet existe */ PUBLIC int USERINFO::makobjpath ( const char *projet, char *path) const { int ret = -1; assert (objpath!=NULL); path_make (objpath,projet,path); if (file_type(path)==1) ret = 0; return ret; } /* Indique si les objets sont conserv‚ dans un r‚pertoire diff‚rent de celui des sources. */ PUBLIC int USERINFO::difusrobj() const { return strcmp(objpath,usrpath)!=0; } /* Indique si l'environnement d‚crit est celui utilis‚e pour intr‚gration. */ PUBLIC VIRTUAL int USERINFO::isbuild() const { return 0; } /* Obtient le nom du programmeur. */ PUBLIC const char *USERINFO::getnom() const { return prog; } /* Obtient le path du systŠme d'archivage. */ PUBLIC const char *USERINFO::getgroupe() const { return groupe; } /* Obtient le path du systŠme qui contient toutes les combinaisons de versions. */ PUBLIC const char *USERINFO::getombre() const { return ombre; } /* Obtient le path de l'environnement de livraison. */ PUBLIC const char *USERINFO::getlivre() const { return livre; } /* Obtient le num‚ro du programmeur. */ PUBLIC int USERINFO::getno() const { return noprog; } /* Obtient la version sur laquelle le programmeur travail. Retourne NULL si pas encore choisie. */ PUBLIC const char *USERINFO::getversion() const { return version[0] == '\0' ? (char*)NULL : version; } /* Associe l'usager … une nouvelle r‚vision. Conserve mˆme nom de version. Transforme tous les paths pour tenir compte de ce nouvel environnement. Retourne != 0 si ok. */ PUBLIC int USERINFO::setversion(const char *newver) { char path[MAXSIZ_PATH]; /* Parfois usrpath contient le r‚pertoire r‚vision, parfois simplement le home de l'usager. exemple: parfois usrpath == k:\usr\jacques\_0_2 et parfois simplement k:\usr\jacques On reconnait ‡a quand la r‚vision est nulle. */ if (rev.isnull()){ // On est pas associ‚ … aucune r‚vision encore strcpy (path,usrpath); }else{ // Il contenait effectivement un path de r‚vision path_splitlex (usrpath,path,NULL); } rev.set (newver); rev.formatpath (revpath); path_make (path,revpath,path); if (usrpath != NULL) free (usrpath); usrpath = strdup_err (path); // On a la version, on peut chercher les objets findobj(); return 1; } /* Associe l'usager … une nouvelle r‚vision et nouveau nom de version. Transforme tous les paths pour tenir compte de ce nouvel environnement. Retourne != 0 si ok. */ PUBLIC int USERINFO::setversion(const VERSION_ONE *one) { char buf[MAXSIZ_PATH]; one->rev.format(buf); int ret = setversion (buf); strcpy (version,one->getversion()); return ret; } /* Obtient le r‚pertoire de l'usager qui contient les r‚pertoires r‚vision */ PUBLIC void USERINFO::gethome(char *path) const { strcpy (path,usrpath); // usrpath pointe g‚n‚ralement dans la racine d'un r‚vision // soit dans un sous-r‚pertoire du r‚pertoire home. if (version[0] != '\0'){ path_splitlex (path,path,NULL); } } /* Obtient le r‚pertoire commun (kit/build) */ PUBLIC void USERINFO::getbld(char *path) const { strcpy (path,build); } /* Retourne vrai si le répertoire /kit/build n'existe pas Pour les projets a un seul programmeur ou un seul programmeur par location, cela est le cas. */ PUBLIC bool USERINFO::nobuild() const { char tmp[PATH_MAX]; getbld (tmp); return file_type (tmp)!=1; } /* Obtient la r‚vision de provenance dans l'archive. */ PUBLIC VIRTUAL const REVISION *USERINFO::getrevsrc() const { return &rev; } /* Obtient la r‚vision destination dans l'environnement de compilation. La plupart du temps, c'est la mˆme chose que getrevsrc(), sauf pour un int‚gration. */ PUBLIC VIRTUAL const REVISION *USERINFO::getrevdst() const { return &rev; } /* D‚termine le prochaine r‚vision pour la livraison. Le num‚ro de livraison d‚pend du num‚ro courant. */ PUBLIC VIRTUAL void USERINFO::setrevnxt( REVISION *newrev, REVISION_TYPE revtype) const { *newrev = rev; newrev->next (getno(),revtype); } /* Assure que tous les champs sont minimalement initialis‚. */ PRIVATE void USERINFO::init() { version[0] = '\0'; revpath[0] = '\0'; prog[0] = '\0'; noprog = 0; usrpath = NULL; objpath = NULL; groupe = NULL; ombre = NULL; build = NULL; livre = NULL; sync = NULL; } /* Variation pour tricher. Ca sert pour bootrcs.c */ PUBLIC USERINFO::USERINFO ( const char *_prog, // Programmeur const char *_version, // Version const char *_usrpath, // path incluant le version const char *_groupe, // R‚pertoire archive const char *_ombre, // R‚pertoire pour extraction const char *_livre, // R‚pertoire pour copie de la livraison // ou NULL. const char *_sync) // R‚pertoire pour copie de la livraison // ou NULL. { init(); strcpy (prog,_prog); noprog = prog_getnum(prog); strcpy (version,_version); usrpath = strdup_err (_usrpath); objpath = NULL; groupe = strdup_err (_groupe); ombre = strdup_err (_ombre); build = userinfo_chkenv("KITBUILD",KITBUILD); if (_livre != NULL){ livre = strdup_err (_livre); }else{ livre = userinfo_chkenv("KITLIVRE",KITLIVRE); } if (_sync != NULL){ sync = strdup_err (_sync); }else{ sync = userinfo_chkenv("KITSYNC",KITSYNC); } } /* Variation pour d‚rivation. */ PROTECTED USERINFO::USERINFO() { init(); } static char * near userinf_dup(const char *pt) { char *ret = NULL; if (pt != NULL) ret = strdup_err(pt); return ret; } /* Permet de duplicater une USERINFO. G‚n‚ralement, on utilisera setversion pour changer de version courante. */ PUBLIC USERINFO::USERINFO(const USERINFO *user) { init(); usrpath = userinf_dup(user->usrpath); objpath = userinf_dup(user->objpath); groupe = userinf_dup(user->groupe); ombre = userinf_dup(user->ombre); build = userinf_dup(user->build); livre = userinf_dup(user->livre); sync = userinf_dup(user->sync); strcpy (version,user->version); strcpy (revpath,user->revpath); rev = user->rev; strcpy (prog,user->prog); noprog = user->noprog; } PUBLIC VIRTUAL USERINFO::~USERINFO () { free (usrpath); free (objpath); free (groupe); free (ombre); free (build); free (livre); free (sync); }