/* like strncasecmp but ignores ws characters */ static int httpHeaderStrCmp(const char *h1, const char *h2, int len) { int len1 = 0; int len2 = 0; assert(h1 && h2); /* fast check first */ if (!strncasecmp(h1, h2, len)) return 0; while (1) { const char c1 = xtoupper(h1[len1 += xcountws(h1 + len1)]); const char c2 = xtoupper(h2[len2 += xcountws(h2 + len2)]); if (c1 < c2) return -len1; if (c1 > c2) return +len1; if (!c1 && !c2) return 0; if (c1) len1++; if (c2) len2++; } /* NOTREACHED */ return 0; }
void strupper(char *s) { while (*s) { /* * #if !defined(KANJI_WIN95_COMPATIBILITY) * if(lp_client_code_page() == KANJI_CODEPAGE) * { * * if (is_shift_jis (*s)) * { * if (is_sj_lower (s[0], s[1])) * s[1] = sj_toupper2 (s[1]); * s += 2; * } * else if (is_kana (*s)) * { * s++; * } * else * { * if (islower(*s)) * *s = toupper(*s); * s++; * } * } * else * #endif *//* KANJI_WIN95_COMPATIBILITY */ { if (islower((int)(unsigned char)*s)) *s = xtoupper(*s); s++; } } }
/* makes a null-terminated string upper-case. Changes CONTENTS! */ static void uc(char *string) { char *p = string, c; while ((c = *p)) { *p = xtoupper(c); p++; } }
static int make_month(const char *s) { int i; char month[3]; month[0] = xtoupper(*s); month[1] = xtolower(*(s + 1)); month[2] = xtolower(*(s + 2)); for (i = 0; i < 12; i++) if (!strncmp(month_names[i], month, 3)) return i; return -1; }
SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle, char *server, char *NTdomain) { SMB_Handle_Type con; char called[80], calling[80], *address; int i; /* Get a connection structure if one does not exist */ con = Con_Handle; if (Con_Handle == NULL) { if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { SMBlib_errno = SMBlibE_NoSpace; return NULL; } } /* Init some things ... */ strcpy(con->service, ""); strcpy(con->username, ""); strcpy(con->password, ""); strcpy(con->sock_options, ""); strcpy(con->address, ""); strcpy(con->desthost, server); strcpy(con->PDomain, NTdomain); strcpy(con->OSName, SMBLIB_DEFAULT_OSNAME); strcpy(con->LMType, SMBLIB_DEFAULT_LMTYPE); con->first_tree = con->last_tree = NULL; SMB_Get_My_Name(con->myname, sizeof(con->myname)); con->port = 0; /* No port selected */ /* Get some things we need for the SMB Header */ con->pid = getpid(); con->mid = con->pid; /* This will do for now ... */ con->uid = 0; /* Until we have done a logon, no uid ... */ con->gid = getgid(); /* Now connect to the remote end, but first upper case the name of the * service we are going to call, sine some servers want it in uppercase */ for (i = 0; i < strlen(server); i++) called[i] = xtoupper(server[i]); called[strlen(server)] = 0; /* Make it a string */ for (i = 0; i < strlen(con->myname); i++) calling[i] = xtoupper(con->myname[i]); calling[strlen(con->myname)] = 0; /* Make it a string */ if (strcmp(con->address, "") == 0) address = con->desthost; else address = con->address; con->Trans_Connect = RFCNB_Call(called, calling, address, /* Protocol specific */ con->port); /* Did we get one? */ if (con->Trans_Connect == NULL) { if (Con_Handle == NULL) { Con_Handle = NULL; free(con); } SMBlib_errno = -SMBlibE_CallFailed; return NULL; } return (con); }
SMB_Handle_Type SMB_Connect(SMB_Handle_Type Con_Handle, SMB_Tree_Handle * tree, char *service, char *username, char *password) { SMB_Handle_Type con; char *host, *address; char temp[80], called[80], calling[80]; int i; /* Get a connection structure if one does not exist */ con = Con_Handle; if (Con_Handle == NULL) { if ((con = (struct SMB_Connect_Def *) malloc(sizeof(struct SMB_Connect_Def))) == NULL) { SMBlib_errno = SMBlibE_NoSpace; return NULL; } } /* Init some things ... */ strcpy(con->service, service); strcpy(con->username, username); strcpy(con->password, password); strcpy(con->sock_options, ""); strcpy(con->address, ""); strcpy(con->PDomain, SMBLIB_DEFAULT_DOMAIN); strcpy(con->OSName, SMBLIB_DEFAULT_OSNAME); strcpy(con->LMType, SMBLIB_DEFAULT_LMTYPE); con->first_tree = con->last_tree = NULL; SMB_Get_My_Name(con->myname, sizeof(con->myname)); con->port = 0; /* No port selected */ /* Get some things we need for the SMB Header */ con->pid = getpid(); con->mid = con->pid; /* This will do for now ... */ con->uid = 0; /* Until we have done a logon, no uid */ con->gid = getgid(); /* Now figure out the host portion of the service */ strcpy(temp, service); /* AI - Added (char *) to stop compiler warnings */ host = (char *) strtok(temp, "/\\"); /* Separate host name portion */ strcpy(con->desthost, host); /* Now connect to the remote end, but first upper case the name of the * service we are going to call, sine some servers want it in uppercase */ for (i = 0; i < strlen(host); i++) called[i] = xtoupper(host[i]); called[strlen(host)] = 0; /* Make it a string */ for (i = 0; i < strlen(con->myname); i++) calling[i] = xtoupper(con->myname[i]); calling[strlen(con->myname)] = 0; /* Make it a string */ if (strcmp(con->address, "") == 0) address = con->desthost; else address = con->address; con->Trans_Connect = RFCNB_Call(called, calling, address, /* Protocol specific */ con->port); /* Did we get one? */ if (con->Trans_Connect == NULL) { if (Con_Handle == NULL) { free(con); Con_Handle = NULL; } SMBlib_errno = -SMBlibE_CallFailed; return NULL; } /* Now, negotiate the protocol */ if (SMB_Negotiate(con, SMB_Prots_Restrict) < 0) { /* Hmmm what should we do here ... We have a connection, but could not * negotiate ... */ return NULL; } /* Now connect to the service ... */ if ((*tree = SMB_TreeConnect(con, NULL, service, password, "A:")) == NULL) { return NULL; } return (con); }
/* * binding_key() * * analizuje nazwê klawisza i wpisuje akcjê do odpowiedniej mapy. * * 0/-1. */ static int binding_key(struct binding *b, const char *key, int add) { /* debug("Key: %s\n", key); */ if (!xstrncasecmp(key, ("Alt-"), 4)) { unsigned char ch; #define __key(x, y, z) \ if (!xstrcasecmp(key + 4, (x))) { \ b->key = saprintf("Alt-%s", (x)); \ if (add) { \ ncurses_binding_map_meta[y] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); \ if (z) \ ncurses_binding_map_meta[z] = ncurses_binding_map_meta[y]; \ } \ return 0; \ } __key("Enter", 13, 0); __key("Backspace", KEY_BACKSPACE, 127); __key("Home", KEY_HOME, KEY_FIND); __key("End", KEY_END, KEY_SELECT); __key("Delete", KEY_DC, 0); __key("Insert", KEY_IC, 0); __key("Left", KEY_LEFT, 0); __key("Right", KEY_RIGHT, 0); __key("Up", KEY_UP, 0); __key("Down", KEY_DOWN, 0); __key("PageUp", KEY_PPAGE, 0); __key("PageDown", KEY_NPAGE, 0); #undef __key if (xstrlen(key) != 5) return -1; ch = xtoupper(key[4]); b->key = saprintf(("Alt-%c"), ch); /* XXX Alt-Ó ??? */ if (add) { ncurses_binding_map_meta[ch] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); if (xisalpha(ch)) ncurses_binding_map_meta[xtolower(ch)] = ncurses_binding_map_meta[ch]; } return 0; } if (!xstrncasecmp(key, ("Ctrl-"), 5)) { unsigned char ch; // if (xstrlen(key) != 6) // return -1; #define __key(x, y, z) \ if (!xstrcasecmp(key + 5, (x))) { \ b->key = saprintf("Ctrl-%s", (x)); \ if (add) { \ ncurses_binding_map[y] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); \ if (z) \ ncurses_binding_map[z] = ncurses_binding_map[y]; \ } \ return 0; \ } __key("Enter", KEY_CTRL_ENTER, 0); __key("Escape", KEY_CTRL_ESCAPE, 0); __key("Delete", KEY_CTRL_DC, 0); __key("Backspace", KEY_CTRL_BACKSPACE, 0); __key("Tab", KEY_CTRL_TAB, 0); #undef __key ch = xtoupper(key[5]); b->key = saprintf(("Ctrl-%c"), ch); if (add) { if (xisalpha(ch)) ncurses_binding_map[ch - 64] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); else return -1; } return 0; } if (xtoupper(key[0]) == 'F' && atoi(key + 1)) { int f = atoi(key + 1); if (f < 1 || f > 63) return -1; b->key = saprintf(("F%d"), f); if (add) ncurses_binding_map[KEY_F(f)] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); return 0; } #define __key(x, y, z) \ if (!xstrcasecmp(key, (x))) { \ b->key = xstrdup((x)); \ if (add) { \ ncurses_binding_map[y] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); \ if (z) \ ncurses_binding_map[z] = ncurses_binding_map[y]; \ } \ return 0; \ } __key("Enter", 13, 0); __key("Escape", 27, 0); __key("Home", KEY_HOME, KEY_FIND); __key("End", KEY_END, KEY_SELECT); __key("Delete", KEY_DC, 0); __key("Insert", KEY_IC, 0); __key("Backspace", KEY_BACKSPACE, 127); __key("Tab", 9, 0); __key("Left", KEY_LEFT, 0); __key("Right", KEY_RIGHT, 0); __key("Up", KEY_UP, 0); __key("Down", KEY_DOWN, 0); __key("PageUp", KEY_PPAGE, 0); __key("PageDown", KEY_NPAGE, 0); #undef __key return -1; }
/* * Decode an operator/operand type command. * Eventually we switch to an operator subroutine in ex_vops.c. * The work here is setting up a function variable to point * to the routine we want, and manipulation of the variables * wcursor and wdot, which mark the other end of the affected * area. If wdot is zero, then the current line is the other end, * and if wcursor is zero, then the first non-blank location of the * other line is implied. */ void operate(register int c, register int cnt) { register int i = 0; void (*moveop)(int), (*deleteop)(int); void (*opf)(int); bool subop = 0; char *oglobp, *ocurs; register line *addr; line *odot; static int lastFKND, lastFCHR; short d; cell nullcell[1], qmarkcell[2], slashcell[2]; CLOBBGRD(opf); CLOBBGRD(d); qmarkcell[0] = '?'; slashcell[0] = '/'; nullcell[0] = qmarkcell[1] = slashcell[1] = 0; moveop = vmove, deleteop = vdelete; wcursor = cursor; wdot = NOLINE; notecnt = 0; dir = 1; switch (c) { /* * d delete operator. */ case 'd': moveop = vdelete; deleteop = (void (*)(int))beep; break; /* * s substitute characters, like c\040, i.e. change space. */ case 's': ungetkey(' '); subop++; /* fall into ... */ /* * c Change operator. */ case 'c': if (c == 'c' && workcmd[0] == 'C' || workcmd[0] == 'S') subop++; moveop = vchange; deleteop = (void (*)(int))beep; break; /* * ! Filter through a UNIX command. */ case '!': moveop = vfilter; deleteop = (void (*)(int))beep; break; /* * y Yank operator. Place specified text so that it * can be put back with p/P. Also yanks to named buffers. */ case 'y': moveop = vyankit; deleteop = (void (*)(int))beep; break; /* * = Reformat operator (for LISP). */ #ifdef LISPCODE case '=': forbid(!value(LISP)); /* fall into ... */ #endif /* * > Right shift operator. * < Left shift operator. */ case '<': case '>': moveop = vshftop; deleteop = (void (*)(int))beep; break; /* * r Replace character under cursor with single following * character. */ case 'r': vmacchng(1); vrep(cnt); return; default: goto nocount; } vmacchng(1); /* * Had an operator, so accept another count. * Multiply counts together. */ if (xisdigit(peekkey()) && peekkey() != '0') { cnt *= vgetcnt(); Xcnt = cnt; forbid (cnt <= 0); } /* * Get next character, mapping it and saving as * part of command for repeat. */ c = map(getesc(),arrows); if (c == 0) return; if (!subop) *lastcp++ = c; nocount: opf = moveop; switch (c) { /* * b Back up a word. * B Back up a word, liberal definition. */ case 'b': case 'B': dir = -1; /* fall into ... */ /* * w Forward a word. * W Forward a word, liberal definition. */ case 'W': case 'w': wdkind = c & ' '; forbid(llfind(2, cnt, opf, 0) < 0); vmoving = 0; break; /* * E to end of following blank/nonblank word */ case 'E': wdkind = 0; goto ein; /* * e To end of following word. */ case 'e': wdkind = 1; ein: forbid(llfind(3, cnt - 1, opf, 0) < 0); vmoving = 0; break; /* * ( Back an s-expression. */ case '(': dir = -1; /* fall into... */ /* * ) Forward an s-expression. */ case ')': forbid(llfind(0, cnt, opf, (line *) 0) < 0); markDOT(); break; /* * { Back an s-expression, but don't stop on atoms. * In text mode, a paragraph. For C, a balanced set * of {}'s. */ case '{': dir = -1; /* fall into... */ /* * } Forward an s-expression, but don't stop on atoms. * In text mode, back paragraph. For C, back a balanced * set of {}'s. */ case '}': forbid(llfind(1, cnt, opf, (line *) 0) < 0); markDOT(); break; /* * % To matching () or {}. If not at ( or { scan for * first such after cursor on this line. */ case '%': vsave(); i = lmatchp((line *) 0); #ifdef TRACE if (trace) fprintf(trace, "after lmatchp in %, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol)); #endif getDOT(); forbid(!i); if (opf != vmove) if (dir > 0) wcursor += skipright(linebuf, wcursor); else cursor += skipright(linebuf, cursor); else markDOT(); vmoving = 0; break; /* * [ Back to beginning of defun, i.e. an ( in column 1. * For text, back to a section macro. * For C, back to a { in column 1 (~~ beg of function.) */ case '[': dir = -1; /* fall into ... */ /* * ] Forward to next defun, i.e. a ( in column 1. * For text, forward section. * For C, forward to a } in column 1 (if delete or such) * or if a move to a { in column 1. */ case ']': if (!vglobp) forbid(getkey() != c); forbid (Xhadcnt); vsave(); i = lbrack(c, opf); getDOT(); forbid(!i); markDOT(); if (ospeed > B300) hold |= HOLDWIG; break; /* * , Invert last find with f F t or T, like inverse * of ;. */ case ',': forbid (lastFKND == 0); c = xisupper(lastFKND&TRIM) ? xtolower(lastFKND&TRIM) : xtoupper(lastFKND&TRIM); i = lastFCHR; if (vglobp == 0) vglobp = nullcell; subop++; goto nocount; /* * 0 To beginning of real line. */ case '0': wcursor = linebuf; vmoving = 0; break; /* * ; Repeat last find with f F t or T. */ case ';': forbid (lastFKND == 0); c = lastFKND; i = lastFCHR; subop++; goto nocount; /* * F Find single character before cursor in current line. * T Like F, but stops before character. */ case 'F': /* inverted find */ case 'T': dir = -1; /* fall into ... */ /* * f Find single character following cursor in current line. * t Like f, but stope before character. */ case 'f': /* find */ case 't': if (!subop) { i = getesc(); if (i == 0) return; *lastcp++ = i; } if (vglobp == 0) lastFKND = c, lastFCHR = i; for (; cnt > 0; cnt--) forbid (find(i) == 0); vmoving = 0; switch (c) { case 'T': wcursor += skipright(linebuf, wcursor); break; case 't': wcursor += skipleft(linebuf, wcursor); case 'f': fixup: if (moveop != vmove) wcursor += skipright(linebuf, wcursor); break; } break; /* * | Find specified print column in current line. */ case '|': if (Pline == numbline) cnt += 8; vmovcol = cnt; vmoving = 1; wcursor = vfindcol(cnt); break; /* * ^ To beginning of non-white space on line. */ case '^': wcursor = vskipwh(linebuf); vmoving = 0; break; /* * $ To end of line. */ case '$': if (opf == vmove) { vmoving = 1; vmovcol = 20000; } else vmoving = 0; if (cnt > 1) { if (opf == vmove) { wcursor = 0; cnt--; } else wcursor = linebuf; /* This is wrong at EOF */ wdot = dot + cnt; break; } if (linebuf[0]) { wcursor = strend(linebuf) - 1; goto fixup; } wcursor = linebuf; break; /* * h Back a character. * ^H Back a character. */ case 'h': case CTRL('h'): dir = -1; /* fall into ... */ /* * space Forward a character. */ case 'l': case ' ': forbid (margin() || opf == vmove && edge()); while (cnt > 0 && !margin()) { wcursor += dir>0 ? skipright(linebuf, wcursor) : skipleft(linebuf, wcursor); cnt--; } if (margin() && opf == vmove || wcursor < linebuf) wcursor -= dir; vmoving = 0; break; /* * D Delete to end of line, short for d$. */ case 'D': cnt = INF; goto deleteit; /* * X Delete character before cursor. */ case 'X': dir = -1; /* fall into ... */ deleteit: /* * x Delete character at cursor, leaving cursor where it is. */ case 'x': if (margin()) goto errlab; vmacchng(1); while (cnt > 0 && !margin()) { wcursor += dir > 0 ? skipright(linebuf, wcursor) : skipleft(linebuf, wcursor); cnt--; } opf = deleteop; vmoving = 0; break; default: /* * Stuttered operators are equivalent to the operator on * a line, thus turn dd into d_. */ if (opf == vmove || c != workcmd[0]) { errlab: beep(); vmacp = 0; return; } /* fall into ... */ /* * _ Target for a line or group of lines. * Stuttering is more convenient; this is mostly * for aesthetics. */ case '_': wdot = dot + cnt - 1; vmoving = 0; wcursor = 0; break; /* * H To first, home line on screen. * Count is for count'th line rather than first. */ case 'H': wdot = (dot - vcline) + cnt - 1; if (opf == vmove) markit(wdot); vmoving = 0; wcursor = 0; break; /* * - Backwards lines, to first non-white character. */ case '-': wdot = dot - cnt; vmoving = 0; wcursor = 0; break; /* * ^P To previous line same column. Ridiculous on the * console of the VAX since it puts console in LSI mode. */ case 'k': case CTRL('p'): wdot = dot - cnt; if (vmoving == 0) vmoving = 1, vmovcol = lcolumn(cursor); wcursor = 0; break; /* * L To last line on screen, or count'th line from the * bottom. */ case 'L': wdot = dot + vcnt - vcline - cnt; if (opf == vmove) markit(wdot); vmoving = 0; wcursor = 0; break; /* * M To the middle of the screen. */ case 'M': wdot = dot + ((vcnt + 1) / 2) - vcline - 1; if (opf == vmove) markit(wdot); vmoving = 0; wcursor = 0; break; /* * + Forward line, to first non-white. * * CR Convenient synonym for +. */ case '+': case CR: wdot = dot + cnt; vmoving = 0; wcursor = 0; break; /* * ^N To next line, same column if possible. * * LF Linefeed is a convenient synonym for ^N. */ case CTRL('n'): case 'j': case NL: wdot = dot + cnt; if (vmoving == 0) vmoving = 1, vmovcol = lcolumn(cursor); wcursor = 0; break; /* * n Search to next match of current pattern. */ case 'n': vglobp = vscandir; c = *vglobp++; goto nocount; /* * N Like n but in reverse direction. */ case 'N': vglobp = vscandir[0] == '/' ? qmarkcell : slashcell; c = *vglobp++; goto nocount; /* * ' Return to line specified by following mark, * first white position on line. * * ` Return to marked line at remembered column. */ case '\'': case '`': d = c; c = getesc(); if (c == 0) return; c = markreg(c); forbid (c == 0); wdot = getmark(c); forbid (wdot == NOLINE); forbid (Xhadcnt); vmoving = 0; wcursor = d == '`' ? ncols[c - 'a'] : 0; if (opf == vmove && (wdot != dot || (d == '`' && wcursor != cursor))) markDOT(); if (wcursor) { vsave(); getline(*wdot); if (wcursor > strend(linebuf)) wcursor = 0; getDOT(); } if (ospeed > B300) hold |= HOLDWIG; break; /* * G Goto count'th line, or last line if no count * given. */ case 'G': if (!Xhadcnt) cnt = lineDOL(); wdot = zero + cnt; forbid (wdot < one || wdot > dol); if (opf == vmove) markit(wdot); vmoving = 0; wcursor = 0; break; /* * / Scan forward for following re. * ? Scan backward for following re. */ case '/': case '?': forbid (Xhadcnt); vsave(); ocurs = cursor; odot = dot; wcursor = 0; if (readecho(c)) return; if (!vglobp) vscandir[0] = genbuf[0]; oglobp = globp; CP(vutmp, genbuf); globp = vutmp; d = peekc; fromsemi: ungetchar(0); fixech(); CATCH addr = address(cursor); ONERR slerr: globp = oglobp; dot = odot; cursor = ocurs; ungetchar(d); splitw = 0; vclean(); vjumpto(dot, ocurs, 0); return; ENDCATCH if (globp == 0) globp = ""; else if (peekc) --globp; if (*globp == ';') { /* /foo/;/bar/ */ globp++; dot = addr; cursor = loc1; goto fromsemi; } dot = odot; ungetchar(d); c = 0; if (*globp == 'z') globp++, c = '\n'; if (any(*globp, "^+-.")) c = *globp++; i = 0; while (xisdigit(*globp&TRIM)) i = i * 10 + *globp++ - '0'; if (any(*globp, "^+-.")) c = *globp++; if (*globp) { /* random junk after the pattern */ beep(); goto slerr; } globp = oglobp; splitw = 0; vmoving = 0; wcursor = loc1; if (i != 0) vsetsiz(i); if (opf == vmove) { if (state == ONEOPEN || state == HARDOPEN) outline = destline = WBOT; if (addr != dot || loc1 != cursor) markDOT(); if (loc1 > linebuf && *loc1 == 0) loc1--; if (c) vjumpto(addr, loc1, c); else { vmoving = 0; if (loc1) { vmoving++; vmovcol = column(loc1); } getDOT(); if (state == CRTOPEN && addr != dot) vup1(); vupdown(addr - dot, NOSTR); } return; } lastcp[-1] = 'n'; getDOT(); wdot = addr; break; } /* * Apply. */ if (vreg && wdot == 0) wdot = dot; (*opf)(c); wdot = NOLINE; }