Advanced Exercises


10.

Assume that your buffer contains the C code shown here, with the Major mode set for C and the cursor positioned at the end of the while line as shown by the black square:

/* * Copy string s2 to s1.  s1 must be large enough * return s1 */ char * strcpy(s1, s2) register char *s1, *s2; {      register char *os1;      os1 = s1;      while (*s1++ = *s2++)      ; return(os1); } /* Copy source into dest, stopping after '\0' is copied, and    return a pointer to the '\0' at the end of dest.  Then our caller    can concatenate to the dest string without another strlen call. */ char * stpcpy (dest, source)      char *dest;      char *source; {  while ((*dest++ = *source++) != '\0')      ; /* void loop body */  return (dest - 1); } 


  1. Which command moves the cursor to the opening brace of strcpy? Which command moves the cursor past the closing brace? Can you use these commands to skip through the buffer in one-procedure steps?

  2. Assume the cursor is just past the closing parenthesis of the while condition. How do you move to the matching opening parenthesis? How do you move back to the matching close parenthesis again? Does the same command set work for matched [] and {}? How does this differ from the vim % command?

  3. One procedure is indented in the Berkeley indention style; the other is indented in the GNU style. Which command reindents a line in accordance with the current indention style you have set up? How would you reindent an entire procedure?

  4. Suppose that you want to write five string procedures and intend to use strcpy as a starting point for further editing. How would you make five copies of the strcpy procedure?

  5. How would you compile the code without leaving emacs?




A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net