/* * C4 -- CVS like front end to the Perforce p4 SCM tool. * * Copyright (c) 1997, Neil Russell. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Neil Russell. * 4. The name Neil Russell may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY NEIL RUSSELL ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL NEIL RUSSELL BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Work space (client) management (incomplete). */ #include "defs.h" /**************************************************/ /* * Mkws command. */ typedef struct ws ws; struct ws { char * desc; char * port; ws * next; }; static ws * wss; static int wsscnt; static void add_ws(char * desc, char * port) { ws * wp; ws * last; for (last = wss; last && last->next; last = last->next) ; wp = Alloc(sizeof (ws)); wp->desc = Alloc(strlen(desc) + 1); strcpy(wp->desc, desc); if (port) { wp->port = Alloc(strlen(port) + 1); strcpy(wp->port, port); } else wp->port = (char *)0; if (wss) last->next = wp; else wss = wp; wp->next = (ws *)0; wsscnt++; } static void read_ws_file(char * f) { FILE * fd; char line[1024]; fd = fopen(f, "r"); if (!fd) Error(1, "can't open %s", f); while (fgets(line, sizeof line, fd)) { char * desc; char * port; char * p; p = line; /* * Ignore comment lines. */ if (*p == '#') continue; /* * Get port address. */ port = p; while (*p && *p != ' ' && *p != '\t' && *p != '\n') p++; /* * Ignore line if we didn't find a port address * at the very beginning of the line. */ if (port == p) continue; /* * Complete port string. */ *p++ = '\0'; /* * Skip space. */ while (*p == ' ' || *p == '\t') p++; /* * Get desciption. */ desc = p; while (*p && *p != '\n') p++; /* * Ignore line if not a complete line or the * description is not a complete description. */ if (*p != '\n' || desc == p) continue; /* * Complete the desciption. */ *p = '\0'; /* * Add it to the list. */ add_ws(desc, port); } } static ws * get_ws(int n) { ws * wp; wp = wss; while (wp && n-- > 0) wp = wp->next; return wp; } static void ask_ws(void) { int rows; int cols; int width; char port[128]; char client_name[128]; char text[128]; /* * We make up to four columns of 22 entries (24x80), then * we start to increase the number of rows */ if (wsscnt > 66) cols = 3; else cols = wsscnt / 22 + 1; rows = wsscnt + cols - 1; rows /= cols; /* * Calculate the width of each column. Start with a width of * 80, then subtract 4 spaces for each column gap, then split * for each column, then 5 spaces for the entry number. */ width = 79; width -= 4 * (cols - 1); width /= cols; width -= 5; /* * Depot selection loop. */ for (;;) { int r, c; int sel; ws * wp; /* * Display the selections. */ for (r = 0; r < rows; r++) { for (c = 0; c < cols; c++) { int x; ws * wp; x = c * rows + r; wp = get_ws(x); if (wp) printf("%3d. %*.*s", x, -width, width, wp->desc); if (c < cols - 1) printf(" "); } printf("\n"); } printf("\nSelection? "); fgets(text, sizeof text, stdin); if (text[0] == '\n' || text[0] == '\0') continue; sel = atoi(text); if (sel >= 0 && sel < wsscnt) { wp = get_ws(sel); strcpy(port, wp->port); break; } } printf("Port name (%s)? ", port); fgets(text, sizeof text, stdin); if (text[0] != '\n' && text[0] != '\0') { char * p; if (p = strchr(text, '\n')) *p = '\0'; strcpy(port, text); } printf("Client name? "); fgets(text, sizeof text, stdin); if (text[0] != '\n' && text[0] != '\0') { char * p; if (p = strchr(text, '\n')) *p = '\0'; strcpy(client_name, text); } else client_name[0] = '\0'; { FILE * fd; fd = fopen(C4TAG, "w"); if (!fd) Error(1, "cant create c4 tag file (" C4TAG ")"); fprintf(fd, "P4PORT=%s\n", port); fprintf(fd, "P4CLIENT=%s\n", client_name); fclose(fd); } } void MakeWorkspace(char ** argv) { /* * Add the "Other" entry. */ add_ws("Other", "perforce:1666"); /* * Construct the list. */ if (!*argv) add_ws("Default server", "perforce:1666"); else read_ws_file(*argv); /* * Get the users' request. */ ask_ws(); exit(0); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 159 | Neil Russell |
C4 integrated into //public/perforce/utils/c4. This is version 1.4 of C4, ready for release. |
||
#1 | 18 | Perforce maintenance | Add c4, a CVS-like frontend to p4 |