/* ARGSUSED */ int undo(int f GCC_UNUSED, int n GCC_UNUSED) { int status; L_NUM before; TRACE((T_CALLED "undo(%d,%d)\n", f, n)); if ((status = check_editable(curbp)) == TRUE) { before = vl_line_count(curbp); if ((status = undoworker(curbp->b_udstkindx)) == TRUE) { if (!line_report(before)) { mlwrite("[change %sdone]", curbp->b_udstkindx == BACK ? "un" : "re"); } curbp->b_udstkindx ^= 1; /* flip to other stack */ } else { mlwarn("[No changes to undo]"); } } returnCode(status); }
/*============================================================================= Function process_page Purpose: to search the given page for matches as specified in the command line parameters. Parameters: *sad (IN) - prepared sockaddr structure *host (IN) - the host we are connecting to port (IN) - the port we are connecting to *fullpath (IN) - the path to the resource we are requesting from host *url - URL for page *server_context - server part of URL for relative hyperlinks *full_context - server and path part of URL for relative hyperlinks depth - search depth of page Returns: nothing, processes the page giving proper reports and adding links to the pages to be spidered if under specified depth =============================================================================*/ void process_page(struct sockaddr *sad, char *host, char *fullpath, char *url, char *server_context, char *full_context, int depth) { int sd, done, line, new_bytes, num_bytes, line_match, page_match, start, end; char get_request[MAX_URL + strlen("GET HTTP/1.0\r\n\r\n")]; char buf[MAX_BUF+1]; /* +1 to let us read MAX_BUF and still null terminate */ if ((sd=socket(PF_INET, SOCK_STREAM, 0))==-1) { printf("unable to create socket\n"); exit(1); } if (my_connect(sd,sad,sizeof(*sad),connect_timeout)<0) { close(sd); if (errno==EINTR) printf("connect to %s timed out\n",host); else printf("unable to connect to %s\n",host); return; } sprintf(get_request,"GET %s HTTP/1.0\r\n\r\n",fullpath); #ifdef DEBUG printf(" sending request: %s",get_request); #endif if (send_all(sd,get_request,strlen(get_request))<strlen(get_request)) { printf("problem sending GET request\n"); close(sd); return; } done = line = num_bytes = page_match = 0; while(!done) { /* try to get a full buffer of data */ do { new_bytes = recv(sd,buf+num_bytes,MAX_BUF-num_bytes,0); if (new_bytes>0) num_bytes+=new_bytes; else if (new_bytes==0) done = 1; else if (new_bytes==-1) { printf("problem encountered on recv call\n"); done = 1; } } while (num_bytes<MAX_BUF && !done); buf[num_bytes] = 0; /* terminate for string processing */ line = start = 0; /* process the buffer of data */ while ((end = strcspn(buf+start,"\n"))+start!=num_bytes) { buf[start+end] = 0; /* null terminate */ if (case_independent) line_match = strcasestr(buf+start,pattern) != NULL; else line_match = strstr(buf+start,pattern) != NULL; if (line_match) page_match = 1; if (depth < search_depth) process_hrefs(buf+start, server_context, full_context, depth); line_report(url,line++,buf+start,line_match); start+=end+1; /* position for next search */ } /* calculate bytes left over in buf without /n */ num_bytes -= start; if (done) { /* process the last line, in MOST cases this is </html> */ if (case_independent) line_match = strcasestr(buf+start,pattern) != NULL; else line_match = strstr(buf+start,pattern) != NULL; if (line_match) page_match = 1; if (depth < search_depth) process_hrefs(buf+start, server_context, full_context, depth); line_report(url,line++,buf+start,line_match); } else if (num_bytes==MAX_BUF) { /* full buffer with no \n */ num_bytes = 0; /* allow full buffer read on next pass */ line--; /* adjust line counter back to proper line */ } else if (num_bytes) { /* bytes left in buffer with no \n, reposition */ memmove(buf,buf+start,num_bytes); } else { /* last byte read was \n */ num_bytes = 0; } } close(sd); url_report(url, page_match); }